task groovy << {} def foo = "One million dollars" def myClosure = { println "Hello from a closure" println "The value of foo is $foo" } myClosure()
[vagrant@localhost ud867]$ gradle groovy Hello from a closure The value of foo is One million dollars :groovy BUILD SUCCESSFUL Total time: 6.312 secs
task groovy << {} def doubleIt = { x -> x + x} def applyTwice(func, arg){ func(func(arg)) } def foo = 5 def fooDoubledTwice = applyTwice(doubleIt, foo) println "Applying doubleIt twice to $foo equals $fooDoubledTwice"
[vagrant@localhost ud867]$ gradle groovy Applying doubleIt twice to 5 equals 20 :groovy BUILD SUCCESSFUL Total time: 6.366 secs
task groovy << {} def myList = ["Gradle", "Groovy", "Android"] def printItem = {item -> println "List item: $item"} myList.each(printItem)