grain
grain copied to clipboard
Lang: `curry` operator
The curry
operator takes a function of multiple arguments and transforms it into a single argument function that returns another function that takes more arguments, one at a time.
For example, look at this implementation of an add
function:
let add = (a, b) => a + b
It has type (Number, Number) -> Number
. The resulting function from curry add
would have type (Number) -> (Number) -> Number
.
The curry
operator could also be used inline during a function definition:
let add = curry (a, b) => a + b
This would be the equivalent of writing it this way:
let add = a => b => a + b
In the future, we'll also have the opportunity to optimize this to minimize runtime performance.
hi @ospencer
curry and placeholder is great. when could we use it?
Hey @vkensou, hopefully sometime soon! This would be a breaking change to the language, so potentially in Grain v0.6 which would come near the end of the year.