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

Unified Diff: corelib/src/collection.dart

Issue 10832060: Add reduce to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use Dynamic as type. Created 8 years, 4 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 | « no previous file | corelib/src/implementation/collections.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: corelib/src/collection.dart
diff --git a/corelib/src/collection.dart b/corelib/src/collection.dart
index 719145acab615314900df2e1bd675bf6b97b6340..b6f656a635194edd69dd55aae5c50e27023e316a 100644
--- a/corelib/src/collection.dart
+++ b/corelib/src/collection.dart
@@ -14,15 +14,28 @@ interface Collection<E> extends Iterable<E> {
/**
* Returns a new collection with the elements [: f(e) :]
- * for each element [e] of this collection.
+ * for each element [:e:] of this collection.
*
* Note on typing: the return type of f() could be an arbitrary
* type and consequently the returned collection's
- * typeis Collection.
+ * typeis Collection.
*/
Collection map(f(E element));
/**
+ * Reduce a collection to a single value by iteratively combining each element
+ * of the collection with an existing value using the provided function.
+ * Use [initialValue] as the initial value, and the function [combine] to
+ * create a new value from the previous one and an element.
+ *
+ * Example of calculating the sum of a collection:
+ *
+ * collection.reduce(0, (prev, element) => prev + element);
+ */
+ Dynamic reduce(Dynamic initialValue,
+ Dynamic combine(Dynamic previousValue, E element));
+
+ /**
* Returns a new collection with the elements of this collection
* that satisfy the predicate [f].
*
« no previous file with comments | « no previous file | corelib/src/implementation/collections.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698