Browse Source

added mapi

Nicolas Cannasse 18 years ago
parent
commit
f138d5f0dc
1 changed files with 11 additions and 0 deletions
  1. 11 0
      std/Lambda.hx

+ 11 - 0
std/Lambda.hx

@@ -60,6 +60,17 @@ class Lambda {
 		return l;
 		return l;
 	}
 	}
 
 
+	/**
+		Similar to [map], but also pass an index for each item iterated.
+	**/
+	public static function mapi<A,B>( it : Iterable<A>, f : Int -> A -> B ) : List<B> {
+		var l = new List<B>();
+		var i = 0;
+		for( x in it )
+			l.add(f(i++,x));
+		return l;
+	}
+
 	/**
 	/**
 		Tells if the element is part of an iterable
 		Tells if the element is part of an iterable
 	**/
 	**/