So, not sure if it's a bug or am I not using the operator right.
Maybe.empty<Int>()
.switchIfEmpty { Maybe.just(2) }
.subscribe {
println("got $it")
}
Block above completes without any results as if Maybe is empty. While block below completes successfully with got 2 output.
Maybe.empty<Int>()
.switchIfEmpty(Maybe.just(2))
.subscribe {
println("got $it")
}
From documentation I expect, that both cases should work the same.
The first case creates a lambda that does nothing, courtesy of Kotlin I guess. If written out in Java syntax:
.switchIfEmpty(mo -> { Maybe.just(2); })
where you are supposed to signal on mo according to the Maybe protocol but you just create and throw away a Maybe instance.
You're right, but, lambda does something.
.switchIfEmpty { ... } creates MaybeSource where subscribe is executed and Maybe.just(2) is created, but nothing happens after that.
so in this case:
.switchIfEmpty { it.onSuccess(2) } and .switchIfEmpty(Maybe.just(2)) are the same.
Thanks for pointing out my mistake.
Most helpful comment
The first case creates a lambda that does nothing, courtesy of Kotlin I guess. If written out in Java syntax:
where you are supposed to signal on
moaccording to theMaybeprotocol but you just create and throw away aMaybeinstance.