| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 */ | 139 */ |
| 140 Iterator<E> get iterator; | 140 Iterator<E> get iterator; |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Returns a new lazy [Iterable] with elements that are created by | 143 * Returns a new lazy [Iterable] with elements that are created by |
| 144 * calling `f` on each element of this `Iterable` in iteration order. | 144 * calling `f` on each element of this `Iterable` in iteration order. |
| 145 * | 145 * |
| 146 * This method returns a view of the mapped elements. As long as the | 146 * This method returns a view of the mapped elements. As long as the |
| 147 * returned [Iterable] is not iterated over, the supplied function [f] will | 147 * returned [Iterable] is not iterated over, the supplied function [f] will |
| 148 * not be invoked. The transformed elements will not be cached. Iterating | 148 * not be invoked. The transformed elements will not be cached. Iterating |
| 149 * multiple times over the the returned [Iterable] will invoke the supplied | 149 * multiple times over the returned [Iterable] will invoke the supplied |
| 150 * function [f] multiple times on the same element. | 150 * function [f] multiple times on the same element. |
| 151 * | 151 * |
| 152 * Methods on the returned iterable are allowed to omit calling `f` | 152 * Methods on the returned iterable are allowed to omit calling `f` |
| 153 * on any element where the result isn't needed. | 153 * on any element where the result isn't needed. |
| 154 * For example, [elementAt] may call `f` only once. | 154 * For example, [elementAt] may call `f` only once. |
| 155 */ | 155 */ |
| 156 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => | 156 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => |
| 157 new MappedIterable<E, dynamic/*=T*/>(this, f); | 157 new MappedIterable<E, dynamic/*=T*/>(this, f); |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * Returns a new lazy [Iterable] with all elements that satisfy the | 160 * Returns a new lazy [Iterable] with all elements that satisfy the |
| 161 * predicate [test]. | 161 * predicate [test]. |
| 162 * | 162 * |
| 163 * The matching elements have the same order in the returned iterable | 163 * The matching elements have the same order in the returned iterable |
| 164 * as they have in [iterator]. | 164 * as they have in [iterator]. |
| 165 * | 165 * |
| 166 * This method returns a view of the mapped elements. As long as the | 166 * This method returns a view of the mapped elements. As long as the |
| 167 * returned [Iterable] is not iterated over, the supplied function [test] will | 167 * returned [Iterable] is not iterated over, the supplied function [test] will |
| 168 * not be invoked. Iterating will not cache results, and thus iterating | 168 * not be invoked. Iterating will not cache results, and thus iterating |
| 169 * multiple times over the returned [Iterable] will invoke the supplied | 169 * multiple times over the returned [Iterable] will invoke the supplied |
| 170 * function [test] multiple times on the same element. | 170 * function [test] multiple times on the same element. |
| 171 */ | 171 */ |
| 172 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); | 172 Iterable<E> where(bool test(E element)) => |
| 173 new WhereIterable<E>(this, test); |
| 173 | 174 |
| 174 /** | 175 /** |
| 175 * Expands each element of this [Iterable] into zero or more elements. | 176 * Expands each element of this [Iterable] into zero or more elements. |
| 176 * | 177 * |
| 177 * The resulting Iterable runs through the elements returned | 178 * The resulting Iterable runs through the elements returned |
| 178 * by [f] for each element of this, in iteration order. | 179 * by [f] for each element of this, in iteration order. |
| 179 * | 180 * |
| 180 * The returned [Iterable] is lazy, and calls [f] for each element | 181 * The returned [Iterable] is lazy, and calls [f] for each element |
| 181 * of this every time it's iterated. | 182 * of this every time it's iterated. |
| 182 */ | 183 */ |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 /** | 428 /** |
| 428 * Returns an Iterable that skips leading elements while [test] is satisfied. | 429 * Returns an Iterable that skips leading elements while [test] is satisfied. |
| 429 * | 430 * |
| 430 * The filtering happens lazily. Every new Iterator of the returned | 431 * The filtering happens lazily. Every new Iterator of the returned |
| 431 * Iterable iterates over all elements of `this`. | 432 * Iterable iterates over all elements of `this`. |
| 432 * | 433 * |
| 433 * The returned iterable provides elements by iterating this iterable, | 434 * The returned iterable provides elements by iterating this iterable, |
| 434 * but skipping over all initial elements where `test(element)` returns | 435 * but skipping over all initial elements where `test(element)` returns |
| 435 * true. If all elements satisfy `test` the resulting iterable is empty, | 436 * true. If all elements satisfy `test` the resulting iterable is empty, |
| 436 * otherwise it iterates the remaining elements in their original order, | 437 * otherwise it iterates the remaining elements in their original order, |
| 437 * starting with the first element for which `test(element)` returns false, | 438 * starting with the first element for which `test(element)` returns false. |
| 438 */ | 439 */ |
| 439 Iterable<E> skipWhile(bool test(E value)) { | 440 Iterable<E> skipWhile(bool test(E value)) { |
| 440 return new SkipWhileIterable<E>(this, test); | 441 return new SkipWhileIterable<E>(this, test); |
| 441 } | 442 } |
| 442 | 443 |
| 443 /** | 444 /** |
| 444 * Returns the first element. | 445 * Returns the first element. |
| 445 * | 446 * |
| 446 * Throws a [StateError] if `this` is empty. | 447 * Throws a [StateError] if `this` is empty. |
| 447 * Otherwise returns the first element in the iteration order, | 448 * Otherwise returns the first element in the iteration order, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 */ | 674 */ |
| 674 abstract class BidirectionalIterator<E> implements Iterator<E> { | 675 abstract class BidirectionalIterator<E> implements Iterator<E> { |
| 675 /** | 676 /** |
| 676 * Move back to the previous element. | 677 * Move back to the previous element. |
| 677 * | 678 * |
| 678 * Returns true and updates [current] if successful. Returns false | 679 * Returns true and updates [current] if successful. Returns false |
| 679 * and sets [current] to null if there is no previous element. | 680 * and sets [current] to null if there is no previous element. |
| 680 */ | 681 */ |
| 681 bool movePrevious(); | 682 bool movePrevious(); |
| 682 } | 683 } |
| OLD | NEW |