Hi,
I am trying an example
let arr = [
2, 4, 87, 99, 323, 4, 5, 6, 7, 8, 33, 43, 232
];
let collection: Vec<_> = arr
.iter()
.enumerate()
.filter_map(|(i, elm)| if i % 2 != 0 { Some(elm) } else { None })
.collect();
for elm in collection {
println!("{}", elm);
}
The arguments for filter_map
has to be &(i, elm)
but why is this not a reference? Since I am
iterating over &T
.