Slide 106
Slide 106 text
@glaforge / #dv13groovy
Closures — map / filter / reduce
!44
@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