Skip to content

Instantly share code, notes, and snippets.

View smhdk's full-sized avatar

Semih Dik smhdk

  • İstanbul
View GitHub Profile
@smhdk
smhdk / rxjava-combine-latest-operator-example.kt
Created December 7, 2018 06:24
RxJava CombineLatest Operator Example with Kotlin
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"
}
@smhdk
smhdk / rxjava-switch-on-next-operator-example.kt
Created December 5, 2018 14:24
RxJava SwitchOnNext Operator Example with Kotlin
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")
}
@smhdk
smhdk / rxjava-switchOnNext-operator-example.kt
Last active December 4, 2018 15:25
RxJava SwitchOnNext Operator with Kotlin
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")
}
@smhdk
smhdk / rxjava-zip-operator-example.kt
Created December 4, 2018 14:44
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")
}
@smhdk
smhdk / rxjava-concat-operator-example.kt
Created December 4, 2018 14:21
RxJava Concat Operator Example with Kotlin
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) {
@smhdk
smhdk / rxjava-merge-operator-example.kt
Created December 4, 2018 14:12
RxJava Merge Operator Example with Kotlin
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) {
@smhdk
smhdk / rxjava-takelast-operator-example.kt
Created December 4, 2018 11:58
RxJava TakeLast Operator Example with Kotlin
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")
}
@smhdk
smhdk / rxjava-take-operator-example.kt
Created December 4, 2018 11:54
RxJava Take Operator Example with Kotlin
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")
}
@smhdk
smhdk / rxjava-skip-last-operator-example.kt
Created December 4, 2018 11:39
RxJava SkipLast Operator Example with Kotlin
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")
}
@smhdk
smhdk / rxjava-skip-operator-example.kt
Last active December 4, 2018 11:36
RxJava Skip Operator Example with Kotlin
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")
}