How do I use Singles.zip()? I had a Single.zip() i...
# rx
p
How do I use Singles.zip()? I had a Single.zip() in RxJava and when I converted it to Kotlin and tried to use same with RxKotlin it is showing error for BiFunction
b
Copy code
val first = Single.just(1)
val second = Single.just(2)
Singles.zip(first, second) { f, s -> f + s }
or using Single.zip:
Copy code
val first = Single.just(1)
val second = Single.just(2)
Single.zip(first, second, BiFunction { f, s -> f + s })
a
Also this will work with new type inference:
Copy code
val first = Single.just(1)
val second = Single.just(2)
Single.zip(first, second) { f, s -> f + s }
https://stackoverflow.com/a/50617880/1916449
u
use rxkotlin, it has sugar for this
p
Thanks for the solutions! But I am not able to figure out the last parameter which I was trying with Singles.zip() in RxKotlin
u
the rxkotlin classes are usually plural, so for example
Copy code
Singles.zip(Single.just(""), Single.just("")) { a, b -> a + b}
u
lol, sry
246 Views