| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |