Index: sdk/lib/core/future.dart |
diff --git a/sdk/lib/core/future.dart b/sdk/lib/core/future.dart |
index c14318b9d0e39fecd86b73fc8919d0bfb5d09e5c..8ca6f99a70bbeb96a2033fcc14d8c7ba7fefab49 100644 |
--- a/sdk/lib/core/future.dart |
+++ b/sdk/lib/core/future.dart |
@@ -259,4 +259,19 @@ class Futures { |
} |
return result; |
} |
+ |
+ /// Runs [fn] for each element in [input] in order, moving to the next element |
Siggi Cherem (dart-lang)
2012/11/06 23:23:51
nit: use /** */ docs (for consistency)
nweiz
2012/11/07 20:50:07
Done.
|
+ /// only when the [Future] returned by [fn] completes. Returns a [Future] that |
+ /// completes when all elements have been processed. |
+ /// |
+ /// The return values of all [Future]s are discarded. Any errors will cause the |
Siggi Cherem (dart-lang)
2012/11/06 23:23:51
nit 80 col
Bob Nystrom
2012/11/07 01:09:43
Pub doesn't need a return value, but to be more ge
nweiz
2012/11/07 20:50:07
Done.
nweiz
2012/11/07 20:50:07
I liked this idea when you first proposed it, but
Bob Nystrom
2012/11/07 21:34:05
SGTM.
|
+ /// iteration to stop and will be piped through the return value. |
Siggi Cherem (dart-lang)
2012/11/06 23:23:51
to avoid confusion with the returned values above,
nweiz
2012/11/07 20:50:07
Done.
|
+ static Future forEach(Iterable input, Future fn(element)) { |
Siggi Cherem (dart-lang)
2012/11/06 23:23:51
nit: rename fn as f? (trying to match the signatur
nweiz
2012/11/07 20:50:07
Done.
|
+ var iterator = input.iterator(); |
+ Future nextElement(_) { |
+ if (!iterator.hasNext) return new Future.immediate(null); |
+ return fn(iterator.next()).chain(nextElement); |
+ } |
+ return nextElement(null); |
+ } |
} |