3 ms·
What makes the Go code so verbose isn't so much that you have to type "func()", but rather that you need to list out all the types, as well as the need for an e
by arp242 4y ago
What makes the Go code so verbose isn't so much that you have to type "func()", but rather that you need to list out all the types, as well as the need for an explicit return.
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.
- sivizius 4y agoFor the record: 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();
- satvikpendem 4y agoThe above seems more like valid TypeScript instead.