Ambiguously combining producers

The ambiguous combination of producers is probably the easiest among all combination types. Think of a situation where you're fetching data from two data sources (may be two separate APIs or database tables), and want to proceed with the first one you got and discard the other one. In the imperative programming technique, you would probably be required to write checks for that; however, with RxKotlin, the amb operator is there to hold your back.

The amb operator takes a list of Observable (Iterable<Observable> instance) as parameter, subscribes to all Observables present in the Iterable instance, emits the items that it got from the first Observable it got an emit from, and discards the rest of Observables ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.