Skip to content

Instantly share code, notes, and snippets.

@smhdk
Created December 4, 2018 14:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smhdk/353214ca23c32a8647849b0da0854434 to your computer and use it in GitHub Desktop.
Save smhdk/353214ca23c32a8647849b0da0854434 to your computer and use it in GitHub Desktop.
RxJava Zip Operator Example with Kotlin
val alphabets1 = Observable.intervalRange(0, 1, 1, 1, TimeUnit.SECONDS).map { id -> "A" + id }
val alphabets2 = Observable.intervalRange(0, 2, 2, 1, TimeUnit.SECONDS).map { id -> "B" + id }
Observable.zip(alphabets1, alphabets2,
BiFunction<String, String, String> { t1, t2 -> "$t1 $t2" })
.subscribe(object : Observer<String> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}
override fun onNext(t: String) {
println("onNext: $t")
}
override fun onError(e: Throwable) {
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment