Function rust_examples::collect::collect_initials [−][src]
Expand description
Traverse a collection of input values and apply an effect to item that may fail (take the
first character from each string slice, resulting in an Option<char>).
Here the magic is the sequencing of these effects via collect. This is possible
because std::iter::FromIterator is implemented for the Option type, allowing for
the following transformations:
- Applying an effect on each value of
Vec<&str>, turning it into anIterator<Item = Option<char>> - Turning these effects “inside out” and collecting the items into
Option<Vec<char>>
This efectively realizes Traverse,
in this case for a Vec which is a ‘Functor’ (has a map) and an Option which is
‘Applicative Monad’ (by the realization in Rust std lib).
