Last active
May 26, 2020 13:10
-
-
Save nick3499/a576007e44de4e8932968463c031075d to your computer and use it in GitHub Desktop.
Rust: Filter Range, Map, Collect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[0, 8, 64, 216, 512, 1000, 1728, 2744, 4096, 5832, 8000, 10648, 13824, 17576, 21952]