|
@@ -86,6 +86,30 @@ class Lambda {
|
|
|
l.add(f(i++,x));
|
|
|
return l;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ Concatenate a list of lists.
|
|
|
+
|
|
|
+ The order of elements is preserved.
|
|
|
+ **/
|
|
|
+ public static function flatten<A>( it : Iterable<Iterable<A>> ) : List<A> {
|
|
|
+ var l = new List<A>();
|
|
|
+ for (e in it)
|
|
|
+ for (x in e)
|
|
|
+ l.add(x);
|
|
|
+ return l;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ A composition of map and flatten.
|
|
|
+
|
|
|
+ The order of elements is preserved.
|
|
|
+
|
|
|
+ If `f` is null, the result is unspecified.
|
|
|
+ **/
|
|
|
+ public static function flatMap<A,B>( it : Iterable<A>, f: A -> Iterable<B> ) : List<B> {
|
|
|
+ return Lambda.flatten(Lambda.map(it, f));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
Tells if `it` contains `elt`.
|