https://kotlinlang.org logo
Title
i

iex

12/02/2020, 2:41 PM
I have 2 separate observables that emit respectively success and error for a specific request. I'm wrapping this in a new observable, that triggers the request and returns a
Single
with success/error state. Thinking about how to implement this. Something like
val successObservable: Observable<SomeType>
val errorObservable: Observable<AnotherType> // AnotherType can be mapped into a Throwable

request.flatMap { 
    // First event of successObservable OR errorObservable. successObservable -> just(event), errorObservable -> error(error)
}
Not sure what operators to use here,
zip
with
take(1)
and
startsWith(none)
crossed my mind but it doesn't feel right...
m

MiSikora

12/02/2020, 10:55 PM
successObservable.ambWith(errorObservable).firstOrError()
i

iex

12/03/2020, 1:11 PM
right. Thank you! I had figured
amb
. Need to map the observables too to
Result
(or another common type), since
amb
requires the types to be the same
and then do a
flatMap
to map the result.success to .just and result.error to .error