[ https://issues.apache.org/jira/browse/GROOVY-4998?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-4998: ------------------------------ Fix Version/s: (was: 3.x) 4.x > Real currying support > --------------------- > > Key: GROOVY-4998 > URL: https://issues.apache.org/jira/browse/GROOVY-4998 > Project: Groovy > Issue Type: New Feature > Components: groovy-jdk > Reporter: Kentaro Yoshida > Priority: Major > Fix For: 4.x > > > Hi. > Groovy's Closure have a name of method 'curry'. > But this is not work for a real currying, it work as a partial function > application. > So, I wrote method of 'Real currying'. > Referenced http://en.wikipedia.org/wiki/Currying > {code} > Closure add = {a, b, c -> a + b + c } // Closure of adding 3 arguments. > assert add(1, 2, 3) == realCurry(add)(1)(2)(3) > assert 6 == add(1, 2, 3) > def curriedAdd = realCurry(add) > def curriedAdd_1 = curriedAdd(1) > def curriedAdd_1_2 = curriedAdd_1(2) > def addResult = curriedAdd_1_2(3) > assert 6 == addResult > def realCurry(Closure clos) { > if (clos.maximumNumberOfParameters >= 1) { > return { x -> > def cc = clos.curry(x) > if (cc.maximumNumberOfParameters) realCurry(cc) > else cc() > } > } else { > return clos > } > } > {code} > (It's also published on gist https://gist.github.com/1193548) > I hope this will be adopted to Groovy core. > Thank you. -- This message was sent by Atlassian Jira (v8.3.4#803005)