Chromium Code Reviews| 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 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
|
Lasse Reichstein Nielsen
2013/01/16 15:34:31
Add comment describing purpose of class.
floitsch
2013/01/16 16:11:35
Done.
| |
| 7 /** | 7 class IterableMixinWorkaround { |
| 8 * The [Collections] class implements static methods useful when | |
| 9 * writing a class that implements [Collection] and the [iterator] | |
| 10 * method. | |
| 11 */ | |
| 12 class Collections { | |
| 13 static bool contains(Iterable iterable, var element) { | 8 static bool contains(Iterable iterable, var element) { |
| 14 for (final e in iterable) { | 9 for (final e in iterable) { |
| 15 if (element == e) return true; | 10 if (element == e) return true; |
| 16 } | 11 } |
| 17 return false; | 12 return false; |
| 18 } | 13 } |
| 19 | 14 |
| 20 static void forEach(Iterable iterable, void f(o)) { | 15 static void forEach(Iterable iterable, void f(o)) { |
| 21 for (final e in iterable) { | 16 for (final e in iterable) { |
| 22 f(e); | 17 f(e); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 } else { | 192 } else { |
| 198 buffer.add("${list[0]}"); | 193 buffer.add("${list[0]}"); |
| 199 for (int i = 1; i < list.length; i++) { | 194 for (int i = 1; i < list.length; i++) { |
| 200 buffer.add(separator); | 195 buffer.add(separator); |
| 201 buffer.add("${list[i]}"); | 196 buffer.add("${list[i]}"); |
| 202 } | 197 } |
| 203 } | 198 } |
| 204 return buffer.toString(); | 199 return buffer.toString(); |
| 205 } | 200 } |
| 206 | 201 |
| 202 static Iterable where(Iterable<Object> iterable, bool f(var element)) { | |
| 203 return new WhereIterable(iterable, f); | |
|
Lasse Reichstein Nielsen
2013/01/16 15:34:31
Just make the first argument be type "Iterable" wi
floitsch
2013/01/16 16:11:35
Done.
| |
| 204 } | |
| 205 | |
| 206 static List mappedByList(List<Object> list, f(var element)) { | |
| 207 return new MappedList(list, f); | |
| 208 } | |
| 209 | |
| 210 static List takeList(List<Object> list, int n) { | |
| 211 // TODO(floitsch): missing generic type. | |
|
Lasse Reichstein Nielsen
2013/01/16 15:34:31
It's a workaround, it'll be fixed when we have mix
floitsch
2013/01/16 16:11:35
Replaced with normal comment.
| |
| 212 return new ListView(list, 0, n); | |
| 213 } | |
| 214 | |
| 215 static Iterable takeWhile(Iterable iterable, bool test(var value)) { | |
| 216 // TODO(floitsch): missing generic type. | |
| 217 return new TakeWhileIterable(iterable, test); | |
| 218 } | |
| 219 | |
| 220 static List skipList(List<Object> list, int n) { | |
| 221 // TODO(floitsch): missing generic type. | |
| 222 return new ListView(list, n, null); | |
| 223 } | |
| 224 | |
| 225 static Iterable skipWhile(Iterable iterable, bool test(var value)) { | |
| 226 // TODO(floitsch): missing generic type. | |
| 227 return new SkipWhileIterable(iterable, test); | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 /** | |
| 232 * The [Collections] class implements static methods useful when | |
| 233 * writing a class that implements [Collection] and the [iterator] | |
| 234 * method. | |
| 235 */ | |
| 236 class Collections { | |
| 207 // TODO(jjb): visiting list should be an identityHashSet when it exists | 237 // TODO(jjb): visiting list should be an identityHashSet when it exists |
| 208 | 238 |
| 209 /** | 239 /** |
| 210 * Returns a string representing the specified collection. If the | 240 * Returns a string representing the specified collection. If the |
| 211 * collection is a [List], the returned string looks like this: | 241 * collection is a [List], the returned string looks like this: |
| 212 * [:'[element0, element1, ... elementN]':]. The value returned by its | 242 * [:'[element0, element1, ... elementN]':]. The value returned by its |
| 213 * [toString] method is used to represent each element. If the specified | 243 * [toString] method is used to represent each element. If the specified |
| 214 * collection is not a list, the returned string looks like this: | 244 * collection is not a list, the returned string looks like this: |
| 215 * [:{element0, element1, ... elementN}:]. In other words, the strings | 245 * [:{element0, element1, ... elementN}:]. In other words, the strings |
| 216 * returned for lists are surrounded by square brackets, while the strings | 246 * returned for lists are surrounded by square brackets, while the strings |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 * Returns true if the specified collection contains the specified object | 327 * Returns true if the specified collection contains the specified object |
| 298 * reference. | 328 * reference. |
| 299 */ | 329 */ |
| 300 static _containsRef(Collection c, Object ref) { | 330 static _containsRef(Collection c, Object ref) { |
| 301 for (var e in c) { | 331 for (var e in c) { |
| 302 if (identical(e, ref)) return true; | 332 if (identical(e, ref)) return true; |
| 303 } | 333 } |
| 304 return false; | 334 return false; |
| 305 } | 335 } |
| 306 } | 336 } |
| OLD | NEW |