Index: sdk/lib/core/iterable.dart |
diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart |
index 83618ce3c2f3936a9c59450dad520476f0829182..0fda6f168210abd481b330fcab6e19f422e91fc1 100644 |
--- a/sdk/lib/core/iterable.dart |
+++ b/sdk/lib/core/iterable.dart |
@@ -98,12 +98,31 @@ abstract class Iterable<E> { |
* 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: |
+ * Example of calculating the sum of an iterable: |
* |
- * collection.reduce(0, (prev, element) => prev + element); |
+ * iterable.reduce((prev, element) => prev + element); |
+ * |
+ * *UPCOMING API-CHANGE*: this method will soon be changed to not take |
+ * an initial value: `iterable.reduce(min)`. Use [fold] instead. |
*/ |
+ @deprecated |
dynamic reduce(var initialValue, |
dynamic combine(var previousValue, E element)) { |
+ return fold(initialValue, combine); |
+ } |
+ |
+ /** |
+ * 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 an iterable: |
+ * |
+ * iterable.fold(0, (prev, element) => prev + element); |
+ */ |
+ dynamic fold(var initialValue, |
+ dynamic combine(var previousValue, E element)) { |
var value = initialValue; |
for (E element in this) value = combine(value, element); |
return value; |