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

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: Use Dynamic as type. 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
« no previous file with comments | « runtime/lib/array.dart ('k') | tests/corelib/collection_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Dynamic reduce(Dynamic initialValue,
184 Dynamic combine(Dynamic previousValue, E element)) {
185 return Collections.reduce(this, initialValue, combine);
186 }
187
183 Collection<T> filter(bool f(T element)) { 188 Collection<T> filter(bool f(T element)) {
184 return Collections.filter(this, new GrowableObjectArray<T>(), f); 189 return Collections.filter(this, new GrowableObjectArray<T>(), f);
185 } 190 }
186 191
187 bool every(bool f(T element)) { 192 bool every(bool f(T element)) {
188 return Collections.every(this, f); 193 return Collections.every(this, f);
189 } 194 }
190 195
191 bool some(bool f(T element)) { 196 bool some(bool f(T element)) {
192 return Collections.some(this, f); 197 return Collections.some(this, f);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 T next() { 232 T next() {
228 if (!hasNext()) { 233 if (!hasNext()) {
229 throw const NoMoreElementsException(); 234 throw const NoMoreElementsException();
230 } 235 }
231 return _array[_pos++]; 236 return _array[_pos++];
232 } 237 }
233 238
234 final GrowableObjectArray<T> _array; 239 final GrowableObjectArray<T> _array;
235 int _pos; 240 int _pos;
236 } 241 }
OLDNEW
« no previous file with comments | « runtime/lib/array.dart ('k') | tests/corelib/collection_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698