iberck
1/17/2017 - 6:38 PM

Groovy fors

Groovy fors

Each with index

list.eachWithIndex { item, index ->
}

El índice comienza en 0

Iterar colecciones

Iterar lista con índice, el index comienza en 0

list.eachWithIndex { val, idx ->
   println "${idx}. ${val}"
}

Iterar un map:

ranks.each({key,value -> println "[$key]=$value"})

Iterar fechas (upto, downto)

def from = Calendar.instance
from.set(year: 2019, month: Calendar.FEBRUARY, date: 19)

def to = Calendar.instance
to.set(year: 2019, month: Calendar.FEBRUARY, date: 25)

from.upto(to) { // from (inclusivo) - to (inclusivo)
    println it.format('EEEE')
}