I'm just surprised anonymous fn () { } wasn't the obvious choice for closure.
squares := numbers.
filter(func(x int) bool { return x >= 0 }).
map(func(x int) int { return x * x })
With what I understand to be your suggested Rust syntax, this would still me: let squares: Vec<_> = numbers.iter()
.filter(fn(x: i64) -> bool { x >= 0 })
.map(fn(x: i64) -> i64 { x * x })
.collect();
which is a lot of noise compared to let squares: Vec<_> = numbers.iter().filter(x => x >= 0).map(x => x * x).collect(); let squares: Vec<_> = numbers.iter().filter(fn(x) { x >= 0 }).map(fn(x) { x * x }).collect(); 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();`|arg| arg*2` and also `|arg| { arg * 2 }` I'm not really a fan.