assume stream of txn, where each txn has following fields
{ date, amt, name, merchant }
given txn stream
group by yyyy-mm // fold 1
within group(yyyy-mm); Map to new object Expense(income, spent)
if amount > 0 then income+=amt // conditional fold 2.a
if amount < 0 then spent+=amt // conditional fold 2.b
am wondering what are approach(es) to achieve above in java. Tried below, it falls way short
txns
.stream()
.collect(
Collectors.groupingBy(
Txn::getYearMonth,
Collectors.mapping(
getExpense,
Collectors.toList())));
getexpense is function map I wrote to transform Txn to Expense object.