Trait

Iterator

A type that supplies the elements of a list one at a type.

Details

An iterator encapsulates the necessary state and logic to produce the elements of a possibly unbounded list, one after the other. Elements are returned by next(), which returns either the next element in the list or None if all elements have been returned.

Use Iterator to implement single-pass iteration algorithms that take ownership of the values on which they iterate. You can "step through" the elements of an iterator using a for-loop:

for let x in some_iterator { print(x) }

An Iterator typically does not model a Collection.

Members

Functions

fun next() -> Optional<???> { inout }

Advances to the next element and returns it, or None if no next element exists.