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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 * This method returns a view of the mapped elements. As long as the | 149 * This method returns a view of the mapped elements. As long as the |
150 * returned [Iterable] is not iterated over, the supplied function [f] will | 150 * returned [Iterable] is not iterated over, the supplied function [f] will |
151 * not be invoked. The transformed elements will not be cached. Iterating | 151 * not be invoked. The transformed elements will not be cached. Iterating |
152 * multiple times over the the returned [Iterable] will invoke the supplied | 152 * multiple times over the the returned [Iterable] will invoke the supplied |
153 * function [f] multiple times on the same element. | 153 * function [f] multiple times on the same element. |
154 * | 154 * |
155 * Methods on the returned iterable are allowed to omit calling `f` | 155 * Methods on the returned iterable are allowed to omit calling `f` |
156 * on any element where the result isn't needed. | 156 * on any element where the result isn't needed. |
157 * For example, [elementAt] may call `f` only once. | 157 * For example, [elementAt] may call `f` only once. |
158 */ | 158 */ |
159 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f); | 159 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => |
| 160 new MappedIterable<E, dynamic/*=T*/>(this, f); |
160 | 161 |
161 /** | 162 /** |
162 * Returns a new lazy [Iterable] with all elements that satisfy the | 163 * Returns a new lazy [Iterable] with all elements that satisfy the |
163 * predicate [test]. | 164 * predicate [test]. |
164 * | 165 * |
165 * The matching elements have the same order in the returned iterable | 166 * The matching elements have the same order in the returned iterable |
166 * as they have in [iterator]. | 167 * as they have in [iterator]. |
167 * | 168 * |
168 * This method returns a view of the mapped elements. As long as the | 169 * This method returns a view of the mapped elements. As long as the |
169 * returned [Iterable] is not iterated over, the supplied function [test] will | 170 * returned [Iterable] is not iterated over, the supplied function [test] will |
170 * not be invoked. Iterating will not cache results, and thus iterating | 171 * not be invoked. Iterating will not cache results, and thus iterating |
171 * multiple times over the returned [Iterable] will invoke the supplied | 172 * multiple times over the returned [Iterable] will invoke the supplied |
172 * function [test] multiple times on the same element. | 173 * function [test] multiple times on the same element. |
173 */ | 174 */ |
174 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); | 175 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); |
175 | 176 |
176 /** | 177 /** |
177 * Expands each element of this [Iterable] into zero or more elements. | 178 * Expands each element of this [Iterable] into zero or more elements. |
178 * | 179 * |
179 * The resulting Iterable runs through the elements returned | 180 * The resulting Iterable runs through the elements returned |
180 * by [f] for each element of this, in iteration order. | 181 * by [f] for each element of this, in iteration order. |
181 * | 182 * |
182 * The returned [Iterable] is lazy, and calls [f] for each element | 183 * The returned [Iterable] is lazy, and calls [f] for each element |
183 * of this every time it's iterated. | 184 * of this every time it's iterated. |
184 */ | 185 */ |
185 Iterable expand(Iterable f(E element)) => | 186 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(E element)) => |
186 new ExpandIterable<E, dynamic>(this, f); | 187 new ExpandIterable<E, dynamic/*=T*/>(this, f); |
187 | 188 |
188 /** | 189 /** |
189 * Returns true if the collection contains an element equal to [element]. | 190 * Returns true if the collection contains an element equal to [element]. |
190 * | 191 * |
191 * This operation will check each element in order for being equal to | 192 * This operation will check each element in order for being equal to |
192 * [element], unless it has a more efficient way to find an element | 193 * [element], unless it has a more efficient way to find an element |
193 * equal to [element]. | 194 * equal to [element]. |
194 * | 195 * |
195 * The equality used to determine whether [element] is equal to an element of | 196 * The equality used to determine whether [element] is equal to an element of |
196 * the iterable defaults to the [Object.operator==] of the element. | 197 * the iterable defaults to the [Object.operator==] of the element. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 * for (E element in this) { | 264 * for (E element in this) { |
264 * value = combine(value, element); | 265 * value = combine(value, element); |
265 * } | 266 * } |
266 * return value; | 267 * return value; |
267 * | 268 * |
268 * Example of calculating the sum of an iterable: | 269 * Example of calculating the sum of an iterable: |
269 * | 270 * |
270 * iterable.fold(0, (prev, element) => prev + element); | 271 * iterable.fold(0, (prev, element) => prev + element); |
271 * | 272 * |
272 */ | 273 */ |
273 dynamic fold(var initialValue, | 274 dynamic/*=T*/ fold/*<T>*/(var/*=T*/ initialValue, |
274 dynamic combine(var previousValue, E element)) { | 275 dynamic/*=T*/ combine(var/*=T*/ previousValue, E element)) { |
275 var value = initialValue; | 276 var value = initialValue; |
276 for (E element in this) value = combine(value, element); | 277 for (E element in this) value = combine(value, element); |
277 return value; | 278 return value; |
278 } | 279 } |
279 | 280 |
280 /** | 281 /** |
281 * Checks whether every element of this iterable satisfies [test]. | 282 * Checks whether every element of this iterable satisfies [test]. |
282 * | 283 * |
283 * Checks every element in iteration order, and returns `false` if | 284 * Checks every element in iteration order, and returns `false` if |
284 * any of them make [test] return `false`, otherwise returns `true`. | 285 * any of them make [test] return `false`, otherwise returns `true`. |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 */ | 666 */ |
666 abstract class BidirectionalIterator<E> implements Iterator<E> { | 667 abstract class BidirectionalIterator<E> implements Iterator<E> { |
667 /** | 668 /** |
668 * Move back to the previous element. | 669 * Move back to the previous element. |
669 * | 670 * |
670 * Returns true and updates [current] if successful. Returns false | 671 * Returns true and updates [current] if successful. Returns false |
671 * and sets [current] to null if there is no previous element. | 672 * and sets [current] to null if there is no previous element. |
672 */ | 673 */ |
673 bool movePrevious(); | 674 bool movePrevious(); |
674 } | 675 } |
OLD | NEW |