Is your feature request related to a problem? Please describe.
Kotlin collections provides helper method like sumOf { }, but some methods are defined with the explicit types (there is a Iterable<T>.sumOf(selector: (T) -> Long): Long and a Iterable<T>.sumOf(selector: (T) -> Int): Int for example).
data class Foo(val data: Double)
val fooList = listOf(Foo(0.1), Foo(0.2))
val sum = fooList.sumOf { it.data }
It could be nice to provide those methods for BigInteger and BigDecimal.
Describe the solution you'd like
data class Bar(val data: BigDecimal)
val barList = listOf(Bar(BigDecimal.fromDouble(0.1)), Bar(BigDecimal.fromDouble(0.2)))
val sum = barList.sumOf { it.data }
Describe alternatives you've considered
It's still possible to use fold to compute a sum (just a bit less convenient).
val sum2 = barList.fold(BigDecimal.ZERO) { acc, it -> acc + it.data }
Is your feature request related to a problem? Please describe. Kotlin collections provides helper method like
sumOf { }
, but some methods are defined with the explicit types (there is aIterable<T>.sumOf(selector: (T) -> Long): Long
and aIterable<T>.sumOf(selector: (T) -> Int): Int
for example).It could be nice to provide those methods for BigInteger and BigDecimal.
Describe the solution you'd like
Describe alternatives you've considered
It's still possible to use
fold
to compute a sum (just a bit less convenient).