RosettaCodeData/Task/First-class-functions/Groovy/first-class-functions-2.groovy

9 lines
364 B
Groovy
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
def cube = { it * it * it }
def cubeRoot = { it ** (1/3) }
funcList = [ Math.&sin, Math.&cos, cube ]
inverseList = [ Math.&asin, Math.&acos, cubeRoot ]
2015-02-20 00:35:01 -05:00
println ([funcList, inverseList].transpose().collect { f, finv -> compose(f, finv) }.collect{ it(0.5) })
println ([inverseList, funcList].transpose().collect { finv, f -> compose(finv, f) }.collect{ it(0.5) })