I have a list that I want to filter, and then return an id card with the sum of the amounts:
val totalById = list .filter { it.status == StatusEnum.Active } .groupBy { it.item.id } .mapValues { it.value.sumBy { it.amount } }
"it.amount" is BigDecimal, but it looks like sumBy only Int.
For java 8 it will be:
Collectors.groupingBy(i-> i.getItem().getId(), Collectors.mapping(Item::getAmount, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))))
Is there any way to do this in Kotlin?
source share