Currying is a process of transforming multi argument
functions into a function that takes fewer arguments by fixing some values,
named for the British mathematician and logician Haskell Curry.
Example
def sum = {a, b -> a + b}
def incByOne = sum.curry(1)
As you see above snippet, I defined the function incByOne
by fixing the first argument of closure ‘sum’ to 1.
HelloWorld.groovy
def sum = {a, b -> a + b} def incByOne = sum.curry(1) def result = incByOne(10) println "result : $result"
Output
result : 11
No comments:
Post a Comment