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 |
| 7 /** | 7 /** |
| 8 * This class provides default implementations for Iterables (including Lists). | 8 * This class provides default implementations for Iterables (including Lists). |
| 9 * | 9 * |
| 10 * Once Dart receives Mixins it will be replaced with mixin classes. | 10 * Once Dart receives Mixins it will be replaced with mixin classes. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 buffer.add("${list[i]}"); | 306 buffer.add("${list[i]}"); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 return buffer.toString(); | 309 return buffer.toString(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 static Iterable where(Iterable iterable, bool f(var element)) { | 312 static Iterable where(Iterable iterable, bool f(var element)) { |
| 313 return new WhereIterable(iterable, f); | 313 return new WhereIterable(iterable, f); |
| 314 } | 314 } |
| 315 | 315 |
| 316 static List mappedByList(List list, f(var element)) { | 316 static Iterable mappedByList(List list, f(var element)) { |
|
floitsch
2013/01/30 14:48:44
Add a static Iterable map(Iterable, f) and use tha
Lasse Reichstein Nielsen
2013/01/31 11:33:49
Done.
| |
| 317 // This is currently a List as well as an Iterable. | |
| 317 return new MappedList(list, f); | 318 return new MappedList(list, f); |
| 318 } | 319 } |
| 319 | 320 |
| 320 static List takeList(List list, int n) { | 321 static Iterable takeList(List list, int n) { |
| 321 // The generic type is currently lost. It will be fixed with mixins. | 322 // The generic type is currently lost. It will be fixed with mixins. |
| 323 // This is currently a List as well as an Iterable. | |
| 322 return new ListView(list, 0, n); | 324 return new ListView(list, 0, n); |
| 323 } | 325 } |
| 324 | 326 |
| 325 static Iterable takeWhile(Iterable iterable, bool test(var value)) { | 327 static Iterable takeWhile(Iterable iterable, bool test(var value)) { |
| 326 // The generic type is currently lost. It will be fixed with mixins. | 328 // The generic type is currently lost. It will be fixed with mixins. |
| 327 return new TakeWhileIterable(iterable, test); | 329 return new TakeWhileIterable(iterable, test); |
| 328 } | 330 } |
| 329 | 331 |
| 330 static List skipList(List list, int n) { | 332 static Iterable skipList(List list, int n) { |
| 331 // The generic type is currently lost. It will be fixed with mixins. | 333 // The generic type is currently lost. It will be fixed with mixins. |
| 334 // This is currently a List as well as an Iterable. | |
| 332 return new ListView(list, n, null); | 335 return new ListView(list, n, null); |
| 333 } | 336 } |
| 334 | 337 |
| 335 static Iterable skipWhile(Iterable iterable, bool test(var value)) { | 338 static Iterable skipWhile(Iterable iterable, bool test(var value)) { |
| 336 // The generic type is currently lost. It will be fixed with mixins. | 339 // The generic type is currently lost. It will be fixed with mixins. |
| 337 return new SkipWhileIterable(iterable, test); | 340 return new SkipWhileIterable(iterable, test); |
| 338 } | 341 } |
| 339 | 342 |
| 340 static List reversedList(List l) { | 343 static List reversedList(List l) { |
| 341 return new ReversedListView(l, 0, null); | 344 return new ReversedListView(l, 0, null); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 | 435 |
| 433 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 436 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 434 static String joinList(List list, [String separator]) | 437 static String joinList(List list, [String separator]) |
| 435 => IterableMixinWorkaround.joinList(list, separator); | 438 => IterableMixinWorkaround.joinList(list, separator); |
| 436 | 439 |
| 437 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 440 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 438 static Iterable where(Iterable iterable, bool f(var element)) | 441 static Iterable where(Iterable iterable, bool f(var element)) |
| 439 => IterableMixinWorkaround.where(iterable, f); | 442 => IterableMixinWorkaround.where(iterable, f); |
| 440 | 443 |
| 441 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 444 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 442 static List mappedByList(List list, f(var element)) | 445 static Iterable mappedByList(List list, f(var element)) |
| 443 => IterableMixinWorkaround.mappedByList(list, f); | 446 => IterableMixinWorkaround.mappedByList(list, f); |
| 444 | 447 |
| 445 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 448 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 446 static List takeList(List list, int n) | 449 static Iterable takeList(List list, int n) |
| 447 => IterableMixinWorkaround.takeList(list, n); | 450 => IterableMixinWorkaround.takeList(list, n); |
| 448 | 451 |
| 449 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 452 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 450 static Iterable takeWhile(Iterable iterable, bool test(var value)) | 453 static Iterable takeWhile(Iterable iterable, bool test(var value)) |
| 451 => IterableMixinWorkaround.takeWhile(iterable, test); | 454 => IterableMixinWorkaround.takeWhile(iterable, test); |
| 452 | 455 |
| 453 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 456 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 454 static List skipList(List list, int n) | 457 static Iterable skipList(List list, int n) |
| 455 => IterableMixinWorkaround.skipList(list, n); | 458 => IterableMixinWorkaround.skipList(list, n); |
| 456 | 459 |
| 457 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 460 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
| 458 static Iterable skipWhile(Iterable iterable, bool test(var value)) | 461 static Iterable skipWhile(Iterable iterable, bool test(var value)) |
| 459 => IterableMixinWorkaround.skipWhile(iterable, test); | 462 => IterableMixinWorkaround.skipWhile(iterable, test); |
| 460 | 463 |
| 461 static String collectionToString(Collection c) | 464 static String collectionToString(Collection c) |
| 462 => ToString.collectionToString(c); | 465 => ToString.collectionToString(c); |
| 463 } | 466 } |
| OLD | NEW |