RxJava zipWith IDE error in Kotlin using Android Studio 3.0
You could also use RxKotlin that comes with some small wrappers to hide this kind of noise. Here is an example for the Single.zipWith:
fun <T, U> Single<T>.zipWith(other: SingleSource<U>): Single<Pair<T,U>>
= zipWith(other, BiFunction { t, u -> Pair(t,u) })
Kotlin can't infer the types in that zipWith
lambda.
Use a BiFunction
instead of the lambda:
data class SomeClass(val a: String, val b: Int)
val list = listOf(SomeClass("1", 1), SomeClass("2", 2))
Observable
.fromIterable(list)
.zipWith(Observable.interval(2, TimeUnit.SECONDS),
BiFunction { item: SomeClass, _: Long -> item })
.subscribe { Log.v("someClass", it.toString())