Skip to content

Instantly share code, notes, and snippets.

@nick3499
Last active May 26, 2020 13:10
Show Gist options
  • Save nick3499/a576007e44de4e8932968463c031075d to your computer and use it in GitHub Desktop.
Save nick3499/a576007e44de4e8932968463c031075d to your computer and use it in GitHub Desktop.
Rust: Filter Range, Map, Collect
fn main() {
let rng = 0..30;
let rng_even_cubed = rng.filter(|n| is_even(*n))
.map(|n| n * n * n)
.collect::<Vec<i32>>();
println!("{:?}", rng_even_cubed);
}
fn is_even(n: i32) -> bool {
n % 2 == 0
}
@nick3499
Copy link
Author

[0, 8, 64, 216, 512, 1000, 1728, 2744, 4096, 5832, 8000, 10648, 13824, 17576, 21952]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment