Benoît Liessens
03/03/2023, 1:10 PMfold lambda?
error is Kotlin: Type mismatch: inferred type is Unit but Int was expected
fun <T, Int> Iterable<T>.sum(tx: (T) -> Int): Int {
return map { tx(it) }
.also { it -> println(it) }
.fold(0 as Int) { acc, next -> acc + next }
}Dominaezzz
03/03/2023, 1:16 PM<T, Int>Benoît Liessens
03/03/2023, 1:17 PMSam
03/03/2023, 1:37 PM<T, Int> you have actually made a new generic parameter called Int which is not the same as (and is hiding) the real Int type. If you just drop that generic parameter from the signature, it should work.