Sergii Sergii - 7 days ago 4
Groovy Question

How to simplify groovy loop code

I have an groove code (with some java style elements)

dates.forEach new Consumer<Period>() {
@Override
void accept(Period period) {
println period
}
}


Is it possible to do it simpler?

I would like to have something like

dates.forEach println


or

dates.forEach println date

Answer

Just use

dates.each { println it }