- We have an iterator over
Option<T>. How do we get an iterator over
That depends on what you want to do with the
None values. The easiest one would be
iter.map(|o| o.unwrap). Other options include using
.unwrap() cause panic!() if any of the elems are None ?
I want the None to be dropped, and the Some to be unwrapped.
Sure, as I said, depends on what you want to do with
None. If you want to panic, that’s it
(e) Ok, then look at
I would use an identity
filter_map(|opt| opt). In 1.33, you’ll be able use
std::convert::identity for the mapping function here, as its last example shows.
filter_map is what I want.
The implementation for
flatten is more complicated though, having to treat each item as a full iterator, even though
Option only ever produces one item or nothing. It’s possible the optimizer can still do a good job breaking that down, but I’d rather give it a simpler
This is even more true if you want to switch to rayon’s