Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A collection of values, or "elements", that can be accessed sequentially. | 8 * A collection of values, or "elements", that can be accessed sequentially. |
| 9 * | 9 * |
| 10 * The elements of the iterable are accessed by getting an [Iterator] | 10 * The elements of the iterable are accessed by getting an [Iterator] |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 * | 95 * |
| 96 * As an `Iterable`, `new Iterable.generate(n, generator))` is equivalent to | 96 * As an `Iterable`, `new Iterable.generate(n, generator))` is equivalent to |
| 97 * `const [0, ..., n - 1].map(generator)`. | 97 * `const [0, ..., n - 1].map(generator)`. |
| 98 */ | 98 */ |
| 99 factory Iterable.generate(int count, [E generator(int index)]) { | 99 factory Iterable.generate(int count, [E generator(int index)]) { |
| 100 if (count <= 0) return new EmptyIterable<E>(); | 100 if (count <= 0) return new EmptyIterable<E>(); |
| 101 return new _GeneratorIterable<E>(count, generator); | 101 return new _GeneratorIterable<E>(count, generator); |
| 102 } | 102 } |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * Creates an empty iterable. | |
| 106 * | |
| 107 * The empty iterable has no elements, and iterating it always stops | |
| 108 * immediately. | |
| 109 * | |
| 110 * An empty iterable can be used in places where you always know that | |
| 111 * the iterable you would otherwise is always empty. | |
|
Søren Gjesse
2015/05/21 09:10:06
Seems like there is a word missing after "otherwis
| |
| 112 */ | |
| 113 const factory Iterable.empty() = EmptyIterable<E>; | |
|
kevmoo
2015/05/21 15:07:06
Why is this useful over using `const []`?
Lasse Reichstein Nielsen
2015/05/21 15:16:51
Because const[] is a List, not just an Iterable.
Y
| |
| 114 | |
| 115 /** | |
| 105 * Returns a new `Iterator` that allows iterating the elements of this | 116 * Returns a new `Iterator` that allows iterating the elements of this |
| 106 * `Iterable`. | 117 * `Iterable`. |
| 107 * | 118 * |
| 108 * Iterable classes may specify the iteration order of their elements | 119 * Iterable classes may specify the iteration order of their elements |
| 109 * (for example [List] always iterate in index order), | 120 * (for example [List] always iterate in index order), |
| 110 * or they may leave it unspecified (for example a hash-based [Set] | 121 * or they may leave it unspecified (for example a hash-based [Set] |
| 111 * may iterate in any order). | 122 * may iterate in any order). |
| 112 * | 123 * |
| 113 * Each time `iterator` is read, it returns a new iterator, | 124 * Each time `iterator` is read, it returns a new iterator, |
| 114 * which can be used to iterate through all the elements again. | 125 * which can be used to iterate through all the elements again. |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 */ | 665 */ |
| 655 abstract class BidirectionalIterator<E> implements Iterator<E> { | 666 abstract class BidirectionalIterator<E> implements Iterator<E> { |
| 656 /** | 667 /** |
| 657 * Move back to the previous element. | 668 * Move back to the previous element. |
| 658 * | 669 * |
| 659 * Returns true and updates [current] if successful. Returns false | 670 * Returns true and updates [current] if successful. Returns false |
| 660 * and sets [current] to null if there is no previous element. | 671 * and sets [current] to null if there is no previous element. |
| 661 */ | 672 */ |
| 662 bool movePrevious(); | 673 bool movePrevious(); |
| 663 } | 674 } |
| OLD | NEW |