grain icon indicating copy to clipboard operation
grain copied to clipboard

Lang: `curry` operator

Open ospencer opened this issue 4 years ago • 2 comments

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.

ospencer avatar Oct 22 '20 21:10 ospencer

hi @ospencer
curry and placeholder is great. when could we use it?

vkensou avatar Mar 14 '22 11:03 vkensou

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.

ospencer avatar Mar 14 '22 21:03 ospencer