std.iter
Iterating over collections
Iterators are objects that can be used to traverse collections such as an
Array
or a Map
. Typically iterators are implemented in one of two
ways:
- Internal iterators: these kind of iterators take care of the iteration process and operate using some kind of closure.
- External iterators: these iterators use some kind of cursor stored somewhere and require you to manually advance the iterator.
Both have their benefits and drawbacks. Internal iterators are easy to implement and typically faster, as they don't require the allocation of additional data structures.
External iterators can be composed together, suspended, and later resumed. External iterators can also be turned into internal iterators, while the inverse is not possible unless a language supports some form of coroutines or generators.
Inko uses external iteration. To make it easier to write such iterators, it
provides the Stream
type, which can create iterators from a closure.
Traits
IntoIter | A type that can be moved into an iterator. | |
Iter | A generic iterator over a sequence of values of type |
Classes
Peekable | An iterator that allows looking at the next element in an iterator, without consuming it. | |
Stream | A type for easily creating iterators using closures. |