user2782001 user2782001 - 21 days ago 5
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
year.months​.weeks​.days​.sightings.flatten().sum()