Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/lib/core/iterator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ abstract class Iterator<E> {
* Returns true if [current] contains the next element.
* Returns false if no elements are left.
*
* Invoke [moveNext] to move to the first element and to each
* subsequent element.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeats the behavior mentioned in the class description, but it does make it easier to find this information while only having an Iterator typed variable available.

I'd prefer to phrase it slightly differently (we rarely use "invoke" in documentation, it's too formal). Maybe:

Use the [moveNext] method to move to the next element. This will change the
current value to that of the next element if there is a next element, which is when
[moveNext] returns true. Also use [moveNext] to start the iteration before accessing
the first element.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I misread this as a comment on current.

I'm not sure it's suitable as an addition on moveNext, because the documentation does say that already, but the existing text could probably be rewritten to express the same thing more clearly.

Maybe:

 /**
 * Advances the iterator to the next element of the iteration.
 * 
 * Should be called before reading [current]. It the call to `moveNext` returns
 * `true`, then [current] will contain the next element of the iteration until 
 * `moveNext` is called again. If the call returns `false`, there are no further
 * elements and [current] should not be used any more.
 *
 * It is safe to call [moveNext] after it has already returned `false`, 
 * but it must keep returning `false` and not have any other effect.
 *
 * A call to `moveNext` may throw for various reasons, including a concurrent change
 * to an underlying collection. If that happens, the iterator may be in an inconsistent 
 * state, and any further behavior of the iterator is unspecified, 
 * including the effect of reading [current]. 
 */

How does this read to you?

* It is safe to invoke [moveNext] even when the iterator is already
* positioned after the last element.
* In this case [moveNext] returns false again and has no effect.
Expand Down