Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: sdk/lib/async/future.dart

Issue 2657563003: Add a generic type to Future.forEach. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 /// A type representing values that are either `Future<T>` or `T`. 7 /// A type representing values that are either `Future<T>` or `T`.
8 /// 8 ///
9 /// This class declaration is a public stand-in for an internal 9 /// This class declaration is a public stand-in for an internal
10 /// future-or-value generic type. References to this class are resolved to the 10 /// future-or-value generic type. References to this class are resolved to the
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 * Runs [f] for each element in [input] in order, moving to the next element 411 * Runs [f] for each element in [input] in order, moving to the next element
412 * only when the [Future] returned by [f] completes. Returns a [Future] that 412 * only when the [Future] returned by [f] completes. Returns a [Future] that
413 * completes when all elements have been processed. 413 * completes when all elements have been processed.
414 * 414 *
415 * The return values of all [Future]s are discarded. Any errors will cause the 415 * The return values of all [Future]s are discarded. Any errors will cause the
416 * iteration to stop and will be piped through the returned [Future]. 416 * iteration to stop and will be piped through the returned [Future].
417 * 417 *
418 * If [f] returns a non-[Future], iteration continues immediately. Otherwise 418 * If [f] returns a non-[Future], iteration continues immediately. Otherwise
419 * it waits for the returned [Future] to complete. 419 * it waits for the returned [Future] to complete.
420 */ 420 */
421 static Future forEach(Iterable input, f(element)) { 421 static Future forEach<T>(Iterable<T> input, f(T element)) {
422 Iterator iterator = input.iterator; 422 var iterator = input.iterator;
423 return doWhile(() { 423 return doWhile(() {
424 if (!iterator.moveNext()) return false; 424 if (!iterator.moveNext()) return false;
425 return new Future.sync(() => f(iterator.current)).then((_) => true); 425 return new Future.sync(() => f(iterator.current)).then((_) => true);
426 }); 426 });
427 } 427 }
428 428
429 /** 429 /**
430 * Performs an async operation repeatedly until it returns `false`. 430 * Performs an async operation repeatedly until it returns `false`.
431 * 431 *
432 * The function [f] is called repeatedly while it returns either the [bool] 432 * The function [f] is called repeatedly while it returns either the [bool]
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 if (replacement != null) { 820 if (replacement != null) {
821 error = _nonNullError(replacement.error); 821 error = _nonNullError(replacement.error);
822 stackTrace = replacement.stackTrace; 822 stackTrace = replacement.stackTrace;
823 } 823 }
824 result._completeError(error, stackTrace); 824 result._completeError(error, stackTrace);
825 } 825 }
826 826
827 /** Helper function that converts `null` to a [NullThrownError]. */ 827 /** Helper function that converts `null` to a [NullThrownError]. */
828 Object _nonNullError(Object error) => 828 Object _nonNullError(Object error) =>
829 (error != null) ? error : new NullThrownError(); 829 (error != null) ? error : new NullThrownError();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698