OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart._collection.dev; | 5 part of dart._collection.dev; |
6 | 6 |
7 /** | 7 /** |
8 * Base implementation of a [List] class. | 8 * Base implementation of a [List] class. |
9 * | 9 * |
10 * This class can be used as a mixin. | 10 * This class can be used as a mixin. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 return buffer.toString(); | 201 return buffer.toString(); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); | 205 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); |
206 | 206 |
207 Iterable map(f(E element)) => new MappedListIterable(this, f); | 207 Iterable map(f(E element)) => new MappedListIterable(this, f); |
208 | 208 |
209 reduce(var initialValue, combine(var previousValue, E element)) { | 209 reduce(var initialValue, combine(var previousValue, E element)) { |
| 210 return fold(initialValue, combine); |
| 211 } |
| 212 |
| 213 fold(var initialValue, combine(var previousValue, E element)) { |
210 var value = initialValue; | 214 var value = initialValue; |
211 int length = this.length; | 215 int length = this.length; |
212 for (int i = 0; i < length; i++) { | 216 for (int i = 0; i < length; i++) { |
213 value = combine(value, this[i]); | 217 value = combine(value, this[i]); |
214 if (length != this.length) { | 218 if (length != this.length) { |
215 throw new ConcurrentModificationError(this); | 219 throw new ConcurrentModificationError(this); |
216 } | 220 } |
217 } | 221 } |
218 return value; | 222 return value; |
219 } | 223 } |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 } | 727 } |
724 | 728 |
725 E remove(int key) { | 729 E remove(int key) { |
726 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 730 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
727 } | 731 } |
728 | 732 |
729 void clear() { | 733 void clear() { |
730 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 734 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
731 } | 735 } |
732 } | 736 } |
OLD | NEW |