Skip to content

Instantly share code, notes, and snippets.

@peysal
Created August 25, 2013 23:23
Show Gist options
  • Select an option

  • Save peysal/6336930 to your computer and use it in GitHub Desktop.

Select an option

Save peysal/6336930 to your computer and use it in GitHub Desktop.
groovy introduction closure 1) default it parameter 2) parameter more than 1 3) passing closure to method
def myCodeBlock1 = {println it; it} //closure with 1 parameter
myCodeBlock1("test")
assert myCodeBlock1("test") == "test"
def myCodeBlock2 = {a,b -> a+b}
assert myCodeBlock2(1,2) == 3
def list = ['a','b','c','d']
def newList = []
def clos = { it.toUpperCase() } //accept 1 argument
list.collect( newList, clos ) //passing closure as part of parameter
assert newList == ["A", "B", "C", "D"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment