Argument ordering of fold's and reduce
rvcas opened this issue · comments
I was thinking it could be nicer to have the anonymous function be the last argument for foldl
so that formatting can look nicer and also seeing the initial value before the function feels more ergonomic especially in situations where the anonymous function can span multiple lines.
Current
fn foldl(self: List<a>, with: fn(a, b) -> b, zero: b) -> b
list.foldl(
list,
fn(n, acc) {
// lines
// lines
// lines
n + acc
},
0,
}
Proposed
fn foldl(self: List<a>, initial: b, with: fn(a, b) -> b) -> b
list.foldl(
list,
0,
fn(n, acc) {
// lines
// lines
// lines
n + acc
}
}
I find the former more aesthetically pleasing.
An interesting idea. Would break the stdlib, so that's something for a 2.x.x , but I think that's indeed more aesthetically pleasing; and perhaps also reads better when it comes to the semantic (being the starting value, it makes sense to have it before the continuation).