by throwaway894345 · 5y ago · 0 comments
Could you expand / explain what you actually mean here? Because I can think of multiple interpretations of this prompt which are straight up part of the stdlib, but that I can interpret this description in multiple ways shows the issue.
EDIT: I think this is it: https://news.ycombinator.com/item?id=27050861
std::iter::repeat_with(f).take_while(|elt| elt.is_some()).filter_map(|elt| elt)
Where `.filter_map()` removes the Option layer and `repeat_with` creates an initially infinite iterator from your function `f`.Long time ago, `repeat_with` might not have existed. Maybe you'd do something like this instead for that in Rust 1.0.0: `std::iter::repeat(()).map(|_| f())...`
You prefer to use std::iter::from_fn now that it exists, of course!
To be honest, making a simple iterator adaptor is quite easy too, so you could have a knack at making one you are missing - if you can't find it in std or in the crate itertools already.