https://kotlinlang.org logo
#rx
Title
# rx
p

praful0203

05/29/2020, 6:45 AM
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

bezrukov

05/29/2020, 7:37 AM
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

arekolek

05/29/2020, 8:08 AM
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

ursus

05/29/2020, 5:37 PM
use rxkotlin, it has sugar for this
p

praful0203

05/30/2020, 5:53 PM
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

ursus

05/31/2020, 1:27 AM
the rxkotlin classes are usually plural, so for example
Copy code
Singles.zip(Single.just(""), Single.just("")) { a, b -> a + b}
u

ursus

06/01/2020, 11:32 AM
lol, sry
101 Views