Last updated: Rust 1.17.0, Itertools 0.6.0.
To-do:
How you can help:
I need feedback on what does and doesn't work. Can you understand the summaries? Do they mesh with how you perceive the methods in question work? What other information could/should be included?
If you have any corrections or suggestions, you can file them on the GitHub repository. The canonical source for this page is src/itercheat/itercheat.html
.
Jump to: Generators, Sequences, Free-Standing Sequences, Values, Other, Notes.
This summarises the iterator-related methods defined by the following Rust libraries:
: the Rust standard library. Methods are defined on the std::iter::Iterator
trait.
: the itertools
library. Methods are defined on the itertools::Itertools
trait.
Additional filtering options:
: show unstable methods.
This is intended to be used in one of a few ways:
To keep the summary as compact as possible, various bits of notation and convention are used. An incomplete list is:
Most iterator methods take their first input by-value; those that don't are marked with a out the front of their first argument.
Elements are underlined to indicate that the method will not compute those elements during the course of its own evaluation.
is used to represent a lazily computed sequence; i.e. an iterator.
indicates an iterator where each element is of type T
.
and are used as input sequences (with subscripted letters denoting individual elements).
is used to represent the output sequence in cases where there is no direct mapping of input elements to output elements.
, , and are used to denote specific, but arbitrary, points within sequences.
, , and are used to denote the length of different sequences.
is used to represent a collection of arbitrary type. Typically, the exact type is inferred from context, and can be anything that implements the FromIterator
trait.
is a function which transforms elements.
is a predicate which determines some logical property of elements.
is an arbitrary binary function.
is used to indicate a generic type argument contains relevant information.
is an abbreviation for "where".
Lib | Function | Input | Output | |
---|---|---|---|---|
Std | ||||
IT | ||||
Std | ||||
Std | ||||
IT | ||||
IT | , | |||
IT | , |
Note: these adaptors are only available as free-standing functions, not as methods on Iterator
s.
Lib | Function | Input | Output | |
---|---|---|---|---|
IT | ||||
IT |
,
,
|
|||
IT |
,
,
|
Lib | Method | Description |
---|---|---|
IT | Ensures the items in two iterators match exactly, panicking with a descriptive message on how and where they differ. | |
Std | Lets you act on a sequence by reference; i.e. calls that would normally consume the iterator will no longer do so. Note that this can have slightly unintuitive effects depending on what iterator methods are used on the result. e.g. must necessarily consume one more element than is returned in order to detect the termination condition; this element is consumed and does not remain in the underlying sequence. | |
Std | Returns an iterator which calls Clone::clone on each element of the input. This is commonly used to turn an Iterator<Item=&T> into an Iterator<Item=T> . |
|
IT | Returns all in-order, unique combinations of length without replacement. Each combination is a Vec of length . |
|
IT | Determines where and how two iterators differ. | |
IT | Eagerly executes a closure on each element of the sequence. | |
IT | Returns a thunk which formats each item in the iterator, separated by . | |
IT | Like format , except that it also accepts a callable used to customise the formatting for each item. |
|
Std | Guarantees that once the input returns , it will always return . | |
Std | Calls a closure for each element in a sequence, without modifying the sequence in any way. | |
IT | Allows you to preview (peek at) an unbounded number of future items in the sequence without removing them. | |
IT | Generalises zip for up to 8 iterators. |
|
Std | Allows you to preview (peek at) the next item in the sequence without removing it. | |
IT | Like take_while_ref , but works on peekable iterators rather than cloneable ones. |
|
IT | Creates an iterator where you can "put back" one item. | |
IT | Creates an iterator where you can "put back" an arbitrary number of items. | |
IT | Wraps an iterator such that it can be iterated by multiple handles. | |
IT | Returns all in-order, unique combinations of length without replacement. Each combination is a tuple of length . |
Definitely not absolute beginners!
The problem is that beginner-friendly descriptions of the available iterator methods are long and wordy, which makes them difficult to quickly scan through. Summarising them requires notation, and there are enough different kinds of behaviours that the notation needs to be relatively extensive.
I've tried to keep the notation used as simple as possible, but that can only go so far. My primary concern with this is creating a summary that can be skimmed relatively quickly, not to make iterators accessible to beginners.
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.