1- def toTriple = {n -> n * 3}
what is -> ?
From Groovy in Action:
Informally, a closure can be recognized as a list of statements within curly braces, like any other code block. It optionally has a list of identifiers in order to name the parameters passed to it, with an -> arrow marking the end of the list.
I've not really seen any examples like the one you have posted. This example makes the definition clearer:
And the result of this statement would be:
1
2
3
Each index of the list [1,2,3] becomes the value for entry over the iteration.
2- def f = { list, value -> list << value }
What is << value ? In this situation the << appends the value to the list. So if you did this in the groovy console:
Your list would then become [1,2,3,4]
3- c = { value1 -> def it = 789; [value1, it] }
Why there is semicolon after it delaration ? Because it's a declaration. If you left the semicolon off then groovy would think that [value1, it] was also part of
it. I wouldn't expect to see this syntax much though.
You should pick up Groovy in Action. It's a great book.