Bernhard
03/02/2025, 9:19 AMcontainers.sumOf { it.dataClassImplementingPlus }
Why isn't this working? What am I looking for? Is there anything better than:
containers.map { it.dataClassImplementingPlus }
.fold(DataClassImplementingPlus()) { acc, el -> acc + el },
Joffrey
03/02/2025, 11:04 AMsumOf
extensions for free. You can implement your own like you did, though. I did exactly that there: https://github.com/joffrey-bion/accounting/blob/main/money%2Fsrc%2FcommonMain%2Fkotlin%2Forg%2Fhildan%2Faccounting%2Fmoney%2FAmount.kt#L93Bernhard
03/02/2025, 11:04 AMSzymon Jeziorski
03/03/2025, 10:47 AMreduce
instead of fold
, this way you don't need to create starting accumulator elementBernhard
03/03/2025, 10:47 AMJoffrey
03/03/2025, 10:47 AMSzymon Jeziorski
03/03/2025, 10:50 AMfold
or reduceOrNull
would work depending on the context