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

Side by Side Diff: runtime/lib/array.dart

Issue 10832060: Add reduce to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class ListFactory<E> { 5 class ListFactory<E> {
6 6
7 factory List.from(Iterable<E> other) { 7 factory List.from(Iterable<E> other) {
8 GrowableObjectArray<E> list = new GrowableObjectArray<E>(); 8 GrowableObjectArray<E> list = new GrowableObjectArray<E>();
9 for (final e in other) { 9 for (final e in other) {
10 list.add(e); 10 list.add(e);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 */ 81 */
82 82
83 void forEach(f(E element)) { 83 void forEach(f(E element)) {
84 Collections.forEach(this, f); 84 Collections.forEach(this, f);
85 } 85 }
86 86
87 Collection map(f(E element)) { 87 Collection map(f(E element)) {
88 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f ); 88 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f );
89 } 89 }
90 90
91 reduce(var init, f(var prev, E element)) {
92 return Collections.reduce(this, init, f);
Lasse Reichstein Nielsen 2012/08/08 07:19:14 Same.
Anders Johnsen 2012/08/08 07:56:14 Done / see other comments.
93 }
94
91 Collection<E> filter(bool f(E element)) { 95 Collection<E> filter(bool f(E element)) {
92 return Collections.filter(this, new GrowableObjectArray<E>(), f); 96 return Collections.filter(this, new GrowableObjectArray<E>(), f);
93 } 97 }
94 98
95 bool every(bool f(E element)) { 99 bool every(bool f(E element)) {
96 return Collections.every(this, f); 100 return Collections.every(this, f);
97 } 101 }
98 102
99 bool some(bool f(E element)) { 103 bool some(bool f(E element)) {
100 return Collections.some(this, f); 104 return Collections.some(this, f);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 */ 217 */
214 218
215 void forEach(f(E element)) { 219 void forEach(f(E element)) {
216 Collections.forEach(this, f); 220 Collections.forEach(this, f);
217 } 221 }
218 222
219 Collection map(f(E element)) { 223 Collection map(f(E element)) {
220 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f ); 224 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f );
221 } 225 }
222 226
227 reduce(var init, f(var prev, E element)) {
228 return Collections.reduce(this, init, f);
229 }
230
223 Collection<E> filter(bool f(E element)) { 231 Collection<E> filter(bool f(E element)) {
224 return Collections.filter(this, new GrowableObjectArray<E>(), f); 232 return Collections.filter(this, new GrowableObjectArray<E>(), f);
225 } 233 }
226 234
227 bool every(bool f(E element)) { 235 bool every(bool f(E element)) {
228 return Collections.every(this, f); 236 return Collections.every(this, f);
229 } 237 }
230 238
231 bool some(bool f(E element)) { 239 bool some(bool f(E element)) {
232 return Collections.some(this, f); 240 return Collections.some(this, f);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 if (!hasNext()) { 316 if (!hasNext()) {
309 throw const NoMoreElementsException(); 317 throw const NoMoreElementsException();
310 } 318 }
311 return _array[_pos++]; 319 return _array[_pos++];
312 } 320 }
313 321
314 final List<E> _array; 322 final List<E> _array;
315 final int _length; // Cache array length for faster access. 323 final int _length; // Cache array length for faster access.
316 int _pos; 324 int _pos;
317 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698