从嵌套属性获取总和的Groovier方法

时间:2016-11-18 02:05:10

标签: groovy

有什么比较好的方法呢?

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

1 个答案:

答案 0 :(得分:1)

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