Is there a function in Rust equivalent to Java's Stream.Iterate?

Viewed 1486

Does the Rust standard library have a function that generates an infinite iterator given a seed and a lambda, as the Java 8 Streams provide? If not, what is a similar alternative in Rust?

Stream.iterate(1, x -> 2 * x);
4 Answers

I wonder if

fn main() {
    let x = (1..std::i32::MAX) .map(|x| x*2);

    for i in x {
        println!("{}", i);
    }
}

would be a satisfactory option for you.

Related