瀏覽代碼

moved map from Lambda to List

Nicolas Cannasse 19 年之前
父節點
當前提交
fd03670b13
共有 2 個文件被更改,包括 10 次插入11 次删除
  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;
 		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]
 	**/
 	**/

+ 10 - 0
std/List.hx

@@ -164,4 +164,14 @@ class List<T> {
 		return l2;
 		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;
+	}
 }
 }