Skip to content

Instantly share code, notes, and snippets.

@manute
Last active December 15, 2015 19:29
Show Gist options
  • Save manute/5311752 to your computer and use it in GitHub Desktop.
Save manute/5311752 to your computer and use it in GitHub Desktop.
List Groovy Functional
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