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

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

Issue 9114021: Added method map to Collection interface and all its implementations (except classes generated fr... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 | « frog/utils.dart ('k') | runtime/lib/byte_buffer.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 /** 79 /**
80 * Collection interface. 80 * Collection interface.
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)) {
88 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f );
89 }
90
87 Collection<E> filter(bool f(E element)) { 91 Collection<E> filter(bool f(E element)) {
88 return Collections.filter(this, new GrowableObjectArray<E>(), f); 92 return Collections.filter(this, new GrowableObjectArray<E>(), f);
89 } 93 }
90 94
91 bool every(bool f(E element)) { 95 bool every(bool f(E element)) {
92 return Collections.every(this, f); 96 return Collections.every(this, f);
93 } 97 }
94 98
95 bool some(bool f(E element)) { 99 bool some(bool f(E element)) {
96 return Collections.some(this, f); 100 return Collections.some(this, f);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if (!hasNext()) { 304 if (!hasNext()) {
301 throw const NoMoreElementsException(); 305 throw const NoMoreElementsException();
302 } 306 }
303 return _array[_pos++]; 307 return _array[_pos++];
304 } 308 }
305 309
306 final List<E> _array; 310 final List<E> _array;
307 final int _length; // Cache array length for faster access. 311 final int _length; // Cache array length for faster access.
308 int _pos; 312 int _pos;
309 } 313 }
OLDNEW
« no previous file with comments | « frog/utils.dart ('k') | runtime/lib/byte_buffer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698