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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 * This can be implemented by running through the [iterator], but some classes | 68 * This can be implemented by running through the [iterator], but some classes |
69 * may have more efficient ways of finding the result | 69 * may have more efficient ways of finding the result |
70 * (like [last] or [length] on a [List], or [contains] on a [Set]). | 70 * (like [last] or [length] on a [List], or [contains] on a [Set]). |
71 * | 71 * |
72 * The methods that return another `Iterable` (like [map] and [where]) | 72 * The methods that return another `Iterable` (like [map] and [where]) |
73 * are all *lazy* - they will iterate the original (as necessary) | 73 * are all *lazy* - they will iterate the original (as necessary) |
74 * every time the returned iterable is iterated, and not before. | 74 * every time the returned iterable is iterated, and not before. |
75 * | 75 * |
76 * Since an iterable may be iterated more than once, it's not recommended to | 76 * Since an iterable may be iterated more than once, it's not recommended to |
77 * have detectable side-effects in the iterator. | 77 * have detectable side-effects in the iterator. |
78 * For methods like [map] and [while], the returned iterable will execute the | 78 * For methods like [map] and [where], the returned iterable will execute the |
79 * argument function on every iteration, so those functions should also not | 79 * argument function on every iteration, so those functions should also not |
80 * have side effects. | 80 * have side effects. |
81 */ | 81 */ |
82 abstract class Iterable<E> { | 82 abstract class Iterable<E> { |
83 const Iterable(); | 83 const Iterable(); |
84 | 84 |
85 /** | 85 /** |
86 * Creates an `Iterable` which generates its elements dynamically. | 86 * Creates an `Iterable` which generates its elements dynamically. |
87 * | 87 * |
88 * The generated iterable has [count] elements, | 88 * The generated iterable has [count] elements, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 * | 200 * |
201 * This operation will check each element in order for being equal to | 201 * This operation will check each element in order for being equal to |
202 * [element], unless it has a more efficient way to find an element | 202 * [element], unless it has a more efficient way to find an element |
203 * equal to [element]. | 203 * equal to [element]. |
204 * | 204 * |
205 * The equality used to determine whether [element] is equal to an element of | 205 * The equality used to determine whether [element] is equal to an element of |
206 * the iterable defaults to the [Object.==] of the element. | 206 * the iterable defaults to the [Object.==] of the element. |
207 * | 207 * |
208 * Some types of iterable may have a different equality used for its elements. | 208 * Some types of iterable may have a different equality used for its elements. |
209 * For example, a [Set] may have a custom equality | 209 * For example, a [Set] may have a custom equality |
210 * (see [Set.identical]) that its `contains` uses. | 210 * (see [Set.identity]) that its `contains` uses. |
211 * Likewise the `Iterable` returned by a [Map.keys] call | 211 * Likewise the `Iterable` returned by a [Map.keys] call |
212 * should use the same equality that the `Map` uses for keys. | 212 * should use the same equality that the `Map` uses for keys. |
213 */ | 213 */ |
214 bool contains(Object element) { | 214 bool contains(Object element) { |
215 for (E e in this) { | 215 for (E e in this) { |
216 if (e == element) return true; | 216 if (e == element) return true; |
217 } | 217 } |
218 return false; | 218 return false; |
219 } | 219 } |
220 | 220 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 */ | 645 */ |
646 abstract class BidirectionalIterator<E> implements Iterator<E> { | 646 abstract class BidirectionalIterator<E> implements Iterator<E> { |
647 /** | 647 /** |
648 * Move back to the previous element. | 648 * Move back to the previous element. |
649 * | 649 * |
650 * Returns true and updates [current] if successful. Returns false | 650 * Returns true and updates [current] if successful. Returns false |
651 * and sets [current] to null if there is no previous element. | 651 * and sets [current] to null if there is no previous element. |
652 */ | 652 */ |
653 bool movePrevious(); | 653 bool movePrevious(); |
654 } | 654 } |
OLD | NEW |