Kotlin and RxJava2 zip operator - None of the following functions can be called with the arguments supplied
For some reason using RxJava 1.1.7 it considers explicitly specifying the type of zipper argument as Func3 a redundant SAM-constructor (which it is) and allows you to replace it with a lambda. However, using RxJava 2.1.5 the type changes to Function3 and it no longer recognises it as an interface with a single abstract method (which it still is). I'm not sure why that is.
Regardless, specifying the type of the zipper function will do the trick:
import io.reactivex.functions.Function3
...
fun temp() {
Observable.zip<List<String>, List<Int>, Boolean, Boolean>(updateStringEventsSubject.buffer(trigger),
updateIntEventsSubject.buffer(trigger),
trigger, Function3 { strings, integers, someBoolean -> saveEvents(strings, integers, someBoolean) } )
.subscribe()
}
Note: I managed to get it to work without explicitly specifying the type arguments for Function3
. It may depend on which version of Kotlin or RxJava you're using as to whether it can infer the types. If not you can always be more explicit:
Function3<List<String>, List<Int>, Boolean, Boolean> { ... }
Edit: There's an even easier way: Use io.reactivex.rxkotlin.Observables
instead. It's an inline function that does the ugly type declaration under the hood for us. Then you can just do this:
import io.reactivex.rxkotlin.Observables
...
Observables.zip(updateStringEventsSubject.buffer(trigger),
updateIntEventsSubject.buffer(trigger),
trigger,
::saveEvents)