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

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

Issue 11366111: Make Iterable more powerful (and lazy). (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Undo unintended change. Created 8 years, 1 month 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 | « no previous file | sdk/lib/collection/collections.dart » ('j') | sdk/lib/core/collection.dart » ('J')
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 5
6 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
7 class _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 8
9 factory _ObjectArray(int length) native "ObjectArray_allocate"; 9 factory _ObjectArray(int length) native "ObjectArray_allocate";
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 void forEach(f(E element)) { 66 void forEach(f(E element)) {
67 Collections.forEach(this, f); 67 Collections.forEach(this, f);
68 } 68 }
69 69
70 Collection map(f(E element)) { 70 Collection map(f(E element)) {
71 return Collections.map( 71 return Collections.map(
72 this, new _GrowableObjectArray.withCapacity(length), f); 72 this, new _GrowableObjectArray.withCapacity(length), f);
73 } 73 }
74 74
75 Collection<E> filter(bool f(E element)) {
76 return Collections.filter(this, new _GrowableObjectArray<E>(), f);
77 }
78
75 reduce(initialValue, combine(previousValue, E element)) { 79 reduce(initialValue, combine(previousValue, E element)) {
76 return Collections.reduce(this, initialValue, combine); 80 return Collections.reduce(this, initialValue, combine);
77 } 81 }
78 82
79 Collection<E> filter(bool f(E element)) {
80 return Collections.filter(this, new _GrowableObjectArray<E>(), f);
81 }
82
83 bool every(bool f(E element)) { 83 bool every(bool f(E element)) {
84 return Collections.every(this, f); 84 return Collections.every(this, f);
85 } 85 }
86 86
87 bool some(bool f(E element)) { 87 bool any(bool f(E element)) {
88 return Collections.some(this, f); 88 return Collections.some(this, f);
89 } 89 }
90 90
91 bool get isEmpty { 91 bool get isEmpty {
92 return this.length === 0; 92 return this.length === 0;
93 } 93 }
94 94
95 void sort([Comparator<E> compare = Comparable.compare]) { 95 void sort([Comparator<E> compare = Comparable.compare]) {
96 coreSort(this, compare); 96 coreSort(this, compare);
97 } 97 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (!hasNext) { 306 if (!hasNext) {
307 throw new StateError("No more elements"); 307 throw new StateError("No more elements");
308 } 308 }
309 return _array[_pos++]; 309 return _array[_pos++];
310 } 310 }
311 311
312 final List<E> _array; 312 final List<E> _array;
313 final int _length; // Cache array length for faster access. 313 final int _length; // Cache array length for faster access.
314 int _pos; 314 int _pos;
315 } 315 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/collection/collections.dart » ('j') | sdk/lib/core/collection.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698