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

Unified Diff: corelib/src/implementation/collections.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 | « corelib/src/collection.dart ('k') | corelib/src/implementation/hash_map_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: corelib/src/implementation/collections.dart
diff --git a/corelib/src/implementation/collections.dart b/corelib/src/implementation/collections.dart
index 462d33af2a703382ecf34f320b5b8d8ca1a0913a..7786d3d364f1457d4361282fb304d47ad4a1b4d3 100644
--- a/corelib/src/implementation/collections.dart
+++ b/corelib/src/implementation/collections.dart
@@ -35,6 +35,15 @@ class Collections {
return destination;
}
+ static Dynamic reduce(Iterable iterable,
+ Dynamic initialValue,
+ Dynamic combine(Dynamic previousValue, element)) {
+ for (final element in iterable) {
+ initialValue = combine(initialValue, element);
+ }
+ return initialValue;
+ }
+
static List filter(Iterable source, List destination, bool f(o)) {
for (final e in source) {
if (f(e)) destination.add(e);
« no previous file with comments | « corelib/src/collection.dart ('k') | corelib/src/implementation/hash_map_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698