by arp242 · 3y ago · 0 comments
squares := numbers.
filter(func(x) { x >= 0 }).
map(func(x) { x * x })
let squares: Vec<_> = numbers.iter()
.filter(fn(x) -> { x >= 0 })
.map(fn(x) -> { x * x })
.collect();
You don't necessarily need new syntax for this, although it may help with clarity.The Rust => code is still a bit shorter, but not much and I don't think it matters much.
let squares: Vec<_> = numbers.iter().filter(x => x >= 0).map(x => x * x).collect();
is not valid Rust, but this is: let squares: Vec<_> = numbers.iter().filter(|&&x| x >= 0).map(|x| x * x).collect();