Instantly share code, notes, and snippets.

View rxjava-combine-latest-operator-example.kt
val observable1 = Observable.interval(400, TimeUnit.MILLISECONDS)
val observable2 = Observable.interval(250, TimeUnit.MILLISECONDS)
Observable.combineLatest(
observable1,
observable2,
object : BiFunction<Long, Long, String> {
override fun apply(t1: Long, t2: Long): String {
return "observable1 value: $t1 , observable2 value: $t2"
}
View rxjava-switch-on-next-operator-example.kt
val firstObservable = Observable.interval(600, TimeUnit.MILLISECONDS)
val secondObservable = Observable.interval(100, TimeUnit.MILLISECONDS)
Observable
.switchOnNext(firstObservable.map { it -> secondObservable })
.subscribe(object : Observer<Long> {
override fun onComplete() {
println("onComplete")
}
View rxjava-switchOnNext-operator-example.kt
Observable
.switchOnNext(
Observable.interval(100, TimeUnit.MILLISECONDS).map { i ->
Observable.interval(30, TimeUnit.MILLISECONDS).map { i2 -> i }
})
.take(6)
.subscribe(object : Observer<Long> {
override fun onComplete() {
println("onComplete")
}
View rxjava-zip-operator-example.kt
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")
}
View rxjava-concat-operator-example.kt
val alphabets1 = Observable.intervalRange(0, 3, 1, 1, TimeUnit.SECONDS).map { id -> "A" + id }
val alphabets2 = Observable.intervalRange(0, 3, 2, 1, TimeUnit.SECONDS).map { id -> "B" + id }
Observable.concat(alphabets1, alphabets2)
.subscribe(object : Observer<String> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
View rxjava-merge-operator-example.kt
val alphabets1 = Observable.intervalRange(0, 3, 1, 1, TimeUnit.SECONDS).map { id -> "A" + id }
val alphabets2 = Observable.intervalRange(0, 3, 2, 1, TimeUnit.SECONDS).map { id -> "B" + id }
Observable.merge(alphabets1, alphabets2)
.subscribe(object : Observer<String> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
View rxjava-takelast-operator-example.kt
Observable.just(1, 2, 3, 4, 5, 6, 7, 8)
.takeLast(4)
.subscribe(object : Observer<Int> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}
View rxjava-take-operator-example.kt
Observable.just(1, 2, 3, 4, 5, 6, 7, 8)
.take(4)
.subscribe(object : Observer<Int> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}
View rxjava-skip-last-operator-example.kt
Observable.just(1, 2, 3, 4, 5, 6, 7, 8)
.skipLast(3)
.subscribe(object : Observer<Int> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}
View rxjava-skip-operator-example.kt
Observable.just(1, 2, 3, 4, 5, 6, 7, 8)
.skip(3)
.subscribe(object : Observer<Int> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}