We have a sum function for all the primitive types...
# stdlib
k
We have a sum function for all the primitive types, but not for `BigDecimal`:
Copy code
listOf(1, 2, 3).sum()
listOf(1.toBigDecimal(), 2.toBigDecimal()).sum()  // Error
listOf(1.toBigDecimal(), 2.toBigDecimal()).sumOf { it }  // OK
Since there is already a
sumOf
function specialized for
BigDecimal
, why isn't there a
sum
function for it too?
4
h
Good question. Would be as easy as
Copy code
fun Iterable<BigDecimal>.sum() = this.sumOf { it }
g
I would recommend to report a feature request on Kotlin issue tracker