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

Unified Diff: sdk/lib/_collection_dev/iterable.dart

Issue 13548002: Add Iterable.fold (and Stream.fold) which replace `reduce`. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index 25515a9f9a63f65a5d948ff78162a9bac32458bc..e8a6a956ac1fbb62d61f8260cf789b694dc8e042 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -200,6 +200,10 @@ abstract class ListIterable<E> extends Iterable<E> {
Iterable map(f(E element)) => new MappedListIterable(this, f);
reduce(var initialValue, combine(var previousValue, E element)) {
+ return fold(initialValue, combine);
+ }
+
+ fold(var initialValue, combine(var previousValue, E element)) {
var value = initialValue;
int length = this.length;
for (int i = 0; i < length; i++) {
@@ -670,6 +674,10 @@ class EmptyIterable<E> extends Iterable<E> {
Iterable map(f(E element)) => const EmptyIterable();
reduce(var initialValue, combine(var previousValue, E element)) {
+ return fold(initialValue, combine);
+ }
+
+ fold(var initialValue, combine(var previousValue, E element)) {
return initialValue;
}
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698