Browse Source

moved map from Lambda to List

Nicolas Cannasse 19 years ago
parent
commit
fd03670b13
2 changed files with 10 additions and 11 deletions
  1. 0 11
      std/Lambda.hx
  2. 10 0
      std/List.hx

+ 0 - 11
std/Lambda.hx

@@ -80,17 +80,6 @@ class Lambda<A,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]
 	**/

+ 10 - 0
std/List.hx

@@ -164,4 +164,14 @@ class List<T> {
 		return l2;
 	}
 
+	public function map<X>(f : T -> X) : List<X> {
+		var b = new List();
+		var l = h;
+		while( l != null ) {
+			var v = l[0];
+			l = l[1];
+			b.add(f(v));
+		}
+		return b;
+	}
 }