Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Chain Filter and Map

Start with vec![1, 2, 3, 4, 5, 6]. Filter to keep only numbers greater than 3, then use map to square each one. Collect and print the result.

Expected output:

text
[16, 25, 36]

Hints:

  • Chain: .iter().filter(|x| **x > 3).map(|x| x * x).collect()
  • Filter gives &&i32, so use **x to compare the value
  • Map receives &i32, so x * x works
rust
fn main() {
}