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

Side by Side Diff: runtime/lib/growable_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 GrowableObjectArray<T> implements List<T> { 5 class GrowableObjectArray<T> implements List<T> {
6 factory GrowableObjectArray._uninstantiable() { 6 factory GrowableObjectArray._uninstantiable() {
7 throw const UnsupportedOperationException( 7 throw const UnsupportedOperationException(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 for (int i = 0; i < length; i++) { 173 for (int i = 0; i < length; i++) {
174 f(this[i]); 174 f(this[i]);
175 } 175 }
176 } 176 }
177 177
178 Collection map(f(T element)) { 178 Collection map(f(T element)) {
179 return Collections.map(this, 179 return Collections.map(this,
180 new GrowableObjectArray.withCapacity(length), f); 180 new GrowableObjectArray.withCapacity(length), f);
181 } 181 }
182 182
183 reduce(var init, f(var prev, E element)) {
184 return Collections.reduce(this, init, f);
185 }
186
183 Collection<T> filter(bool f(T element)) { 187 Collection<T> filter(bool f(T element)) {
184 return Collections.filter(this, new GrowableObjectArray<T>(), f); 188 return Collections.filter(this, new GrowableObjectArray<T>(), f);
185 } 189 }
186 190
187 bool every(bool f(T element)) { 191 bool every(bool f(T element)) {
188 return Collections.every(this, f); 192 return Collections.every(this, f);
189 } 193 }
190 194
191 bool some(bool f(T element)) { 195 bool some(bool f(T element)) {
192 return Collections.some(this, f); 196 return Collections.some(this, f);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 T next() { 231 T next() {
228 if (!hasNext()) { 232 if (!hasNext()) {
229 throw const NoMoreElementsException(); 233 throw const NoMoreElementsException();
230 } 234 }
231 return _array[_pos++]; 235 return _array[_pos++];
232 } 236 }
233 237
234 final GrowableObjectArray<T> _array; 238 final GrowableObjectArray<T> _array;
235 int _pos; 239 int _pos;
236 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698