nick34992
4/12/2017 - 6:21 PM

Rust: Filter Range, Map, Collect

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
}