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

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

Issue 14071002: Added new version of reduce. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed more uses of max, and a few bugs. 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
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index 69181b9aa497451d6ad53723a968407c02f3c0af..60777e95c84a06237a691fb224e25c3bacfaa18c 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -126,46 +126,6 @@ abstract class ListIterable<E> extends Iterable<E> {
throw new StateError("No matching element");
}
- E min([int compare(E a, E b)]) {
- if (length == 0) return null;
- if (compare == null) {
- var defaultCompare = Comparable.compare;
- compare = defaultCompare;
- }
- E min = elementAt(0);
- int length = this.length;
- for (int i = 1; i < length; i++) {
- E element = elementAt(i);
- if (compare(min, element) > 0) {
- min = element;
- }
- if (length != this.length) {
- throw new ConcurrentModificationError(this);
- }
- }
- return min;
- }
-
- E max([int compare(E a, E b)]) {
- if (length == 0) return null;
- if (compare == null) {
- var defaultCompare = Comparable.compare;
- compare = defaultCompare;
- }
- E max = elementAt(0);
- int length = this.length;
- for (int i = 1; i < length; i++) {
- E element = elementAt(i);
- if (compare(max, element) < 0) {
- max = element;
- }
- if (length != this.length) {
- throw new ConcurrentModificationError(this);
- }
- }
- return max;
- }
-
String join([String separator = ""]) {
int length = this.length;
if (!separator.isEmpty) {
@@ -199,8 +159,13 @@ 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);
+ E reduce(E combine(var value, E element)) {
+ if (length == 0) throw new StateError("No elements");
+ E value = elementAt(0);
+ for (int i = 1; i < length; i++) {
+ value = combine(value, elementAt(i));
+ }
+ return value;
}
fold(var initialValue, combine(var previousValue, E element)) {
@@ -663,18 +628,14 @@ class EmptyIterable<E> extends Iterable<E> {
throw new StateError("No matching element");
}
- E min([int compare(E a, E b)]) => null;
-
- E max([int compare(E a, E b)]) => null;
-
String join([String separator = ""]) => "";
Iterable<E> where(bool test(E element)) => this;
Iterable map(f(E element)) => const EmptyIterable();
- reduce(var initialValue, combine(var previousValue, E element)) {
- return fold(initialValue, combine);
+ E reduce(E combine(E value, E element)) {
+ throw new StateError("No elements");
}
fold(var initialValue, combine(var previousValue, E element)) {

Powered by Google App Engine
This is Rietveld 408576698