Closed
Description
At the moment, if you want to partially apply a function the only way is to write a closure:
let part = |x, z| foo(x, 42, z);
That isn't to bad, but still more verbose than necessary, so I propose a special sugar for this usage:
let part = foo(_, 42, _);
The rules are simple:
- For the first
_
in an expression, transform the whole expression into a closure by putting an|...|
at the front and replacing the_
with the first argument in there. - For each following
_
in a expression, append an argument to the argument list, and replace the_
with that, too.
This would also allow things like v.map(_ + 5).filter(3 < _)
to work, which read really nice.
Things would get a bit hairy if you involve if
or match
, but each arm would just need the rule to have the same number of _
s. And it would be unidiomatic to use it for bigger code structures anyway.
Metadata
Metadata
Assignees
Labels
No labels