Last active
December 15, 2015 19:29
-
-
Save manute/5311752 to your computer and use it in GitHub Desktop.
List Groovy Functional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiplyBy2 = {element -> element * 2 } | |
/* | |
'collect', is the function to iterate list and return the result apply to the closure | |
*/ | |
assert [1,2,3].collect{ it * 2 } == [2,4,6] | |
assert [1,2,3].collect{ multiplyBy2(it) } == [2,4,6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment