OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 part of dart.core; | |
6 | |
7 /** | |
8 * An interface for getting items, one at a time, from an object. | |
9 * | |
10 * The for-in construct transparently uses `Iterator` to test for the end | |
11 * of the iteration, and to get each item (or _element_). | |
12 * | |
13 * If the object iterated over is changed during the iteration, the | |
14 * behavior is unspecified. | |
15 * | |
16 * The `Iterator` is initially positioned before the first element. | |
17 * Before accessing the first element the iterator must thus be advanced using | |
18 * [moveNext] to point to the first element. | |
19 * If no element is left, then [moveNext] returns false, [current] | |
20 * returns `null`, and all further calls to [moveNext] will also return false. | |
21 * | |
22 * A typical usage of an Iterator looks as follows: | |
23 * | |
24 * var it = obj.iterator; | |
25 * while (it.moveNext()) { | |
26 * use(it.current); | |
27 * } | |
28 * | |
29 * **See also:** | |
30 * [Iteration](http://www.dartlang.org/docs/dart-up-and-running/contents/ch03.ht
ml#iteration) | |
31 * in the [library tour](http://www.dartlang.org/docs/dart-up-and-running/conten
ts/ch03.html) | |
32 */ | |
33 abstract class Iterator<E> { | |
34 /** | |
35 * Moves to the next element. | |
36 * | |
37 * Returns true if [current] contains the next element. | |
38 * Returns false if no elements are left. | |
39 * | |
40 * It is safe to invoke [moveNext] even when the iterator is already | |
41 * positioned after the last element. | |
42 * In this case [moveNext] returns false again and has no effect. | |
43 * | |
44 * A call to `moveNext` may throw if iteration has been broken by | |
45 * changing the underlying collection. | |
46 */ | |
47 bool moveNext(); | |
48 | |
49 /** | |
50 * Returns the current element. | |
51 * | |
52 * Returns `null` if the iterator has not yet been moved to the first | |
53 * element, or if the iterator has been moved past the last element of the | |
54 * [Iterable]. | |
55 * | |
56 * The `current` getter should keep its value until the next call to | |
57 * [moveNext], even if an underlying collection changes. | |
58 * After a successful call to `moveNext`, the user doesn't need to cache | |
59 * the current value, but can keep reading it from the iterator. | |
60 */ | |
61 E get current; | |
62 } | |
OLD | NEW |