def addNumbers = { x, y -> x + y }
def addOne = addNumbers.curry(1)
assert 5 == addOne(4)
Currying is a technique to create a clone of a closure and fixing values for some of the parameters. We can fix one or more parameters, depending on the number of arguments we use for the
curry()
method. The parameters are bound from left to right. The good thing is we can even use other closures as parameters for the curry()
method.
No comments:
Post a Comment