Iterable<T>.reduce() throws exception on empty list


Iterable<T>.reduce() throws an exception when passed an empty list. This is a dangerous behavior - it is really easy to not consider this case when reading/writing code using it.

Common solutions in other languages have you pass in a default result for empty lists, which is quite safe. I’d like to see the same thing in Kotlin.

(Tagged Language Design as it is part of the standard library.)


This behavior not is documented, this should be fixed.

Maybe in the next release: reduceOrNull