In Clojure, I use a function called iterate
that:
Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects
Is there something similar in Rust?
For example, I have this function that I'd like to pass to a function with a number and then iterate over a stream/range/vector until I find Some(1)
:
fn coltz(n: u64) -> Option<u64> {
match n % 2 {
0 => Some(n / 2),
_ => Some(3 * n + 1)
}
}