Slide 101
Slide 101 text
Closures — map / filter / reduce
!40
@groovy.transform.Immutable
class
Person
{
String
name
int
age
}
def
persons
=
[
new
Person('Guillaume',
36),
new
Person('Marion',
5),
new
Person('Erine',
1)
]
def
names
=
persons.findAll
{
it.age
<
18
}
.collect
{
it.name.toUpperCase()
}
.sort()
.join(',
')
assert
names
==
"ERINE,
MARION"
find/findAll, inject, collect,
flatten, min/max, unique,
reverse, collate, groupBy, any/
every, head/tail/last, count/
countBy, combinations/
permutations/subsequences/
transpose, withDefault/
withLazyDefault