Even numbers, will not compile

Why will not this code compile, I am new to Rust just so you now :smile:

I get this error:
cannot be built from an iterator over elements of type 'bool'

fn even_nums(nums: &[i32]) {
  let x: Vec<i32> = nums.iter().map(|num| num % 2 == 0).collect();
  println!("{:?}", x);

It looks like you want filter instead of map


Indeed, filter works better :smiley:
Thank you @andresovela

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.