I have a collection of invoices :
class Invoice { int month; BigDecimal amount }
I\'d like to merge these invoices, so I get one invoice pe
Collection result = invoices.stream().collect(groupingBy(i -> i.month, collectingAndThen( reducing((Invoice i1, Invoice i2) -> new Invoice(i1.month, i1.amount + i2.amount)), Optional::get))).values();