| 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 * An object that uses an [Iterator] to serve objects one at a time. | 8 * An object that uses an [Iterator] to serve objects one at a time. |
| 9 * | 9 * |
| 10 * You can iterate over all objects served by an Iterable object | 10 * You can iterate over all objects served by an Iterable object |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 * | 194 * |
| 195 * When the iterator encounters an element `e` that does not satisfy [test], | 195 * When the iterator encounters an element `e` that does not satisfy [test], |
| 196 * it discards `e` and moves into the finished state. That is, it does not | 196 * it discards `e` and moves into the finished state. That is, it does not |
| 197 * get or provide any more elements. | 197 * get or provide any more elements. |
| 198 */ | 198 */ |
| 199 Iterable<E> takeWhile(bool test(E value)); | 199 Iterable<E> takeWhile(bool test(E value)); |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * Returns an Iterable that skips the first [n] elements. | 202 * Returns an Iterable that skips the first [n] elements. |
| 203 * | 203 * |
| 204 * If `this` has fewer than [n] elements, then the resulting Iterable is | 204 * If `this` has fewer than [n] elements, then the resulting Iterable is |
| 205 * empty. | 205 * empty. |
| 206 * | 206 * |
| 207 * It is an error if [n] is negative. | 207 * It is an error if [n] is negative. |
| 208 */ | 208 */ |
| 209 Iterable<E> skip(int n); | 209 Iterable<E> skip(int n); |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * Returns an Iterable that skips elements while [test] is satisfied. | 212 * Returns an Iterable that skips elements while [test] is satisfied. |
| 213 * | 213 * |
| 214 * The filtering happens lazily. Every new Iterator of the returned | 214 * The filtering happens lazily. Every new Iterator of the returned |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 * | 273 * |
| 274 * If `this` has fewer than [index] elements throws a [RangeError]. | 274 * If `this` has fewer than [index] elements throws a [RangeError]. |
| 275 * | 275 * |
| 276 * Note: if `this` does not have a deterministic iteration order then the | 276 * Note: if `this` does not have a deterministic iteration order then the |
| 277 * function may simply return any element without any iteration if there are | 277 * function may simply return any element without any iteration if there are |
| 278 * at least [index] elements in `this`. | 278 * at least [index] elements in `this`. |
| 279 */ | 279 */ |
| 280 E elementAt(int index); | 280 E elementAt(int index); |
| 281 } | 281 } |
| 282 | 282 |
| 283 | |
| 284 typedef E _Generator<E>(int index); | 283 typedef E _Generator<E>(int index); |
| 285 | 284 |
| 286 class _GeneratorIterable<E> extends IterableBase<E> { | 285 class _GeneratorIterable<E> extends IterableBase<E> |
| 286 implements EfficientLength { |
| 287 final int _count; | 287 final int _count; |
| 288 final _Generator<E> _generator; | 288 final _Generator<E> _generator; |
| 289 _GeneratorIterable(this._count, this._generator); | 289 _GeneratorIterable(this._count, this._generator); |
| 290 Iterator<E> get iterator => new _GeneratorIterator(_count, _generator); | 290 Iterator<E> get iterator => new _GeneratorIterator(_count, _generator); |
| 291 int get length => _count; |
| 291 } | 292 } |
| 292 | 293 |
| 293 class _GeneratorIterator<E> implements Iterator<E> { | 294 class _GeneratorIterator<E> implements Iterator<E> { |
| 294 final int _count; | 295 final int _count; |
| 295 final _Generator<E> _generator; | 296 final _Generator<E> _generator; |
| 296 int _index = 0; | 297 int _index = 0; |
| 297 E _current; | 298 E _current; |
| 298 | 299 |
| 299 _GeneratorIterator(this._count, this._generator); | 300 _GeneratorIterator(this._count, this._generator); |
| 300 | 301 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 317 */ | 318 */ |
| 318 abstract class BidirectionalIterator<E> implements Iterator<E> { | 319 abstract class BidirectionalIterator<E> implements Iterator<E> { |
| 319 /** | 320 /** |
| 320 * Move back to the previous element. | 321 * Move back to the previous element. |
| 321 * | 322 * |
| 322 * Returns true and updates [current] if successful. Returns false | 323 * Returns true and updates [current] if successful. Returns false |
| 323 * and sets [current] to null if there is no previous element. | 324 * and sets [current] to null if there is no previous element. |
| 324 */ | 325 */ |
| 325 bool movePrevious(); | 326 bool movePrevious(); |
| 326 } | 327 } |
| OLD | NEW |