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

Side by Side Diff: sdk/lib/collection/collections.dart

Issue 11412086: Make 'where' lazy. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: FilteredIterable/Iterator -> WhereIterable/Iterator. Created 8 years 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 /** 5 /**
6 * The [Collections] class implements static methods useful when 6 * The [Collections] class implements static methods useful when
7 * writing a class that implements [Collection] and the [iterator] 7 * writing a class that implements [Collection] and the [iterator]
8 * method. 8 * method.
9 */ 9 */
10 class Collections { 10 class Collections {
(...skipping 26 matching lines...) Expand all
37 37
38 static Dynamic reduce(Iterable iterable, 38 static Dynamic reduce(Iterable iterable,
39 Dynamic initialValue, 39 Dynamic initialValue,
40 Dynamic combine(Dynamic previousValue, element)) { 40 Dynamic combine(Dynamic previousValue, element)) {
41 for (final element in iterable) { 41 for (final element in iterable) {
42 initialValue = combine(initialValue, element); 42 initialValue = combine(initialValue, element);
43 } 43 }
44 return initialValue; 44 return initialValue;
45 } 45 }
46 46
47 static List where(Iterable source, List destination, bool f(o)) {
48 for (final e in source) {
49 if (f(e)) destination.add(e);
50 }
51 return destination;
52 }
53
54 static bool isEmpty(Iterable iterable) { 47 static bool isEmpty(Iterable iterable) {
55 return !iterable.iterator.moveNext(); 48 return !iterable.iterator.moveNext();
56 } 49 }
57 50
58 // TODO(jjb): visiting list should be an identityHashSet when it exists 51 // TODO(jjb): visiting list should be an identityHashSet when it exists
59 52
60 /** 53 /**
61 * Returns a string representing the specified collection. If the 54 * Returns a string representing the specified collection. If the
62 * collection is a [List], the returned string looks like this: 55 * collection is a [List], the returned string looks like this:
63 * [:'[element0, element1, ... elementN]':]. The value returned by its 56 * [:'[element0, element1, ... elementN]':]. The value returned by its
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 * Returns true if the specified collection contains the specified object 141 * Returns true if the specified collection contains the specified object
149 * reference. 142 * reference.
150 */ 143 */
151 static _containsRef(Collection c, Object ref) { 144 static _containsRef(Collection c, Object ref) {
152 for (var e in c) { 145 for (var e in c) {
153 if (e === ref) return true; 146 if (e === ref) return true;
154 } 147 }
155 return false; 148 return false;
156 } 149 }
157 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698