Chromium Code Reviews| Index: sdk/lib/core/future.dart |
| diff --git a/sdk/lib/core/future.dart b/sdk/lib/core/future.dart |
| index c14318b9d0e39fecd86b73fc8919d0bfb5d09e5c..e1d5fedc7783ff2fb95491427ed41fb319a09654 100644 |
| --- a/sdk/lib/core/future.dart |
| +++ b/sdk/lib/core/future.dart |
| @@ -259,4 +259,21 @@ class Futures { |
| } |
| return result; |
| } |
| + |
| + /** |
| + * Runs [fn] for each element in [input] in order, moving to the next element |
|
Andrei Mouravski
2012/11/19 21:32:59
Should this be "[f]"?
nweiz
2012/11/19 22:30:08
Yes. 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 |
| + * iteration to stop and will be piped through the returned [Future]. |
| + */ |
| + static Future forEach(Iterable input, Future f(element)) { |
|
floitsch
2012/11/19 10:05:42
I don't think we need/want this function. We shoul
Bob Nystrom
2012/11/19 19:55:07
How about reduce() for the operation that takes a
nweiz
2012/11/19 21:08:15
That wouldn't do the same thing as this function.
nweiz
2012/11/19 21:08:15
In terms of naming, I'd rather see the operation h
|
| + var iterator = input.iterator(); |
| + Future nextElement(_) { |
| + if (!iterator.hasNext) return new Future.immediate(null); |
| + return f(iterator.next()).chain(nextElement); |
| + } |
| + return nextElement(null); |
| + } |
| } |