Sergii Sergii - 2 months ago 14
Groovy Question

How to simplify groovy loop code

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

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

Is it possible to do it simpler?

I would like to have something like

dates.forEach println


dates.forEach println date

Answer Source

Just use

dates.each { println it }