In Groovy, how do I add up the values for a certain property in a map?

Viewed 13619

I have the following map:

def map = [];
map.add([ item: "Shampoo", count: 5 ])
map.add([ item: "Soap", count: 3 ])

I would like to get the sum of all the count properties in the map. In C# using LINQ, it would be something like:

map.Sum(x => x.count)

How do I do the same in Groovy?

3 Answers
Related