I've recently switched to Kotlin 1.5.0 which deprecated sumBy, and in the conversion process I've encountered a strange Exception while analyzing expression error from the compiler.
Here's a minimal code that produces the error, which you can run here:
fun <T> percentify(list: List<T>, fn: (T) -> Boolean): Float {
val okCount = list.sumOf { if (fn(it)) 1 else 0 }
if (list.isEmpty()) return 0f else return okCount/list.size
}
fun main() {
val list = listOf(1, 2, 3)
println(percentify(list) { it % 2 == 1})
}
My question is, am I using sumOf wrong, or is it an issue with the compiler?