user2782001 user2782001 - 11 months ago 68
Groovy Question

Groovier way of getting sum from a nested property

What's the groovier way to do this?

def totalSightings=0;
year.months.each{month->
month.weeks.each{week->
week.days.each{day->
total+=day.sightings;
}
}
}

Answer Source
year.months​.weeks​.days​.sightings.flatten().sum()