map is lazy
examples/vectors/map-is-lazy/src/main.rs
fn main() { let numbers = vec![1, 3, 6]; let double = numbers.into_iter().map(|num| { println!("doubling {num}"); num * 2 }); println!("Nothing happended yet"); for num in double { println!("{num:?}"); } }
Nothing happended yet doubling 1 2 doubling 3 6 doubling 6 12