assert 9 == animals.sum { it.price } // or animals.price.sum()What Groovy you see here: sum can be called on a List and optionally passed a closure defining the property of “it” – the animal being iterated over – to sort on.or sum can be called on a List without any arguments, which is equivalent to invoking the “plus” method on all items in the collection. Optional<BigDecimal> sum = animals. stre