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

Unified Diff: sdk/lib/collection/list.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/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index 62bd84c5345e30111104f108799dc79c86936f01..82b1d900f3137594f3edc0ed0705d7a4ba279eec 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -141,46 +141,6 @@ abstract class ListMixin<E> implements List<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 = this[0];
- int length = this.length;
- for (int i = 1; i < length; i++) {
- E element = this[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 = this[0];
- int length = this.length;
- for (int i = 1; i < length; i++) {
- E element = this[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) {
@@ -214,8 +174,13 @@ abstract class ListMixin<E> implements List<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(E previousValue, E element)) {
+ if (length == 0) throw new StateError("No elements");
+ E value = this[0];
+ for (int i = 1; i < length; i++) {
+ value = combine(value, this[i]);
+ }
+ return value;
}
fold(var initialValue, combine(var previousValue, E element)) {

Powered by Google App Engine
This is Rietveld 408576698