Chaining Maybe in rxjava for "else" or "coallesce"

I'm new to rxjava, so I apologize if this is a stupid question. I have two Maybes (call them A and B) that I want to compose in such a way as to get the 3rd option.

If A succeeds, I want my composite to succeed with the same value. If the errors are A, I want my composite error with the same throws. If A completes without emitting values, I want to then delegate to B.

Is there an easy way to achieve this?

+3


source to share


1 answer


If you don't want specific errors in A, you can use the following:



A
.onErrorResumeNext(Observable.empty())
.switchIfEmpty(B)

      

+3


source







All Articles