Browse Source

added lmap, list

Nicolas Cannasse 19 years ago
parent
commit
34bb340f2f
1 changed files with 22 additions and 1 deletions
  1. 22 1
      std/Lambda.hx

+ 22 - 1
std/Lambda.hx

@@ -39,6 +39,16 @@ class Lambda<A,B> {
 		return a;
 		return a;
 	}
 	}
 
 
+	/**
+		Creates a [List] from an [Iterator]
+	**/
+	public static function list( it : Iterator<A> ) : List<A> {
+		var l = new List<A>();
+		for(i in it)
+			l.add(i);
+		return l;
+	}
+
 	/**
 	/**
 		Creates a new [Iterator] that will apply the function 'f' to all
 		Creates a new [Iterator] that will apply the function 'f' to all
 		elements of the iterator 'it'.
 		elements of the iterator 'it'.
@@ -60,7 +70,7 @@ class Lambda<A,B> {
 	}
 	}
 
 
 	/**
 	/**
-		Creates an [Array] 'b' from an [Array] 'a' by applying the function 'f'
+		Creates an [Array] from an [Array] 'a' by applying the function 'f'
 		on all elements of 'a'.
 		on all elements of 'a'.
 	**/
 	**/
 	public static function amap(a : Array<A>,f : A -> B) : Array<B> {
 	public static function amap(a : Array<A>,f : A -> B) : Array<B> {
@@ -70,6 +80,17 @@ class Lambda<A,B> {
 		return b;
 		return b;
 	}
 	}
 
 
+	/**
+		Creates a [List] from a [List] 'l' by applying the function 'f'
+		on all elements of 'l'.
+	**/
+	public static function lmap(l : List<A>,f : A -> B) : List<B> {
+		var b = new List();
+		for( x in l )
+			b.add(f(x));
+		return b;
+	}
+
 	/**
 	/**
 		Functional 'fold' using an [Iterator]
 		Functional 'fold' using an [Iterator]
 	**/
 	**/