I'm using switchIfEmpty
operator in RxJava to use a secondary observable when the primary observable doesn't have a value. Following is my code:
fun main(args: Array<String>) {
getFirstObservable()
.switchIfEmpty { getSecondObservable() }
.subscribe { println(it) }
}
fun getFirstObservable() = Observable.empty<String>()
fun getSecondObservable() = Observable.just("String1", "String2")
However, even if the first observable is empty, it never emits values from the second observable, and nothing is printed in the output. Am I missing something?