user2782001
user2782001

Reputation: 3488

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;
        }
    }
}

Upvotes: 0

Views: 54

Answers (1)

rvargas
rvargas

Reputation: 635

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

Upvotes: 1

Related Questions