I\'m going a little crazy here. I\'m trying to create an Observable extension function (against RxJava 2.x) to emit the average of the emissio
Type inference mostly does not work for rxJava2. It's not a type inference problem actually. Kotlin usually generates extension methods to that replaces SAM with kotlin functional types, but this technic does not work for overridden methods for some reason.
More details here https://youtrack.jetbrains.com/issue/KT-13609
As an option, you could try to specify types for lambda arguments
fun Observable.average() = publish().autoConnect(2).let {
Single.zip(it.sum().toSingle(), it.count(), BiFunction {
sum: BigDecimal, count: Long ->
sum / BigDecimal.valueOf(count)
})
}