Check out the rest of the series:
Knowing your RxJava Operator Toolbelt 1: Creating Observables
Knowing your RxJava Operator Toolbelt 2: Transforming Observables
Knowing your RxJava Operator Toolbelt 4: Filtering Observables
Knowing your RxJava Operator Toolbelt 5: Utility Observables

RxJava is Java (and Kotlin’s) form of Reactive Programming, and thus Android’s too. It bestows the ultimate power in async operations through the use of observables. If you’re new, check out my Hardly Comprehensive Introduction.

RxJava is a powerful tool that only gets better with how well you know it. It’s got a high skill cap, and how close you get to it is determined by how well you know your operators.

So you know when you want to have two different observables to come together in one single stream? Yeah, that, that is the situation we’re covering.

There’s a few different ways to go ‘combine’ these observables, all differing by the type or order they are emitted to your observer so let’s buckle up and get observing.

Combine Operators

Merge

Merge is your standard run-of-the-mill combine operator. It combines the observables and lets them emit as one.

Output

Concat

Observables emit in order. The observable will wait for any current observable to be fully emitted before starting to emit the next one.

Output

Combine Latest

Whenever an update is made to either observable, the latest items from all observables are emitted via a specified function. It’s a bit more involved as the args supplied by combineLatest are in the Any or Object class so you have to map it yourself, then emissions come in the form of a list of the latest emissions from each observer.

Output

Join

This one is quite involved (and actually a pain to write in Kotlin). When one observable emits, there is a time window for the other to emit (defined by the functions). If the other emits within the specified time window, the results are joined by the Result Selector (the BiFunction) and emitted.

As can be seen, the time window given for when one observable emits first can be different from the other. If the other observable fails to emit during the time window, then the emission is dropped.

The time windows are also independent of each other. Say o1 emits and starts its time window, o2 emits during the time window and the joined result is emitted, but o2’s time window still starts regardless, so if o1 emits again within this time window, another joined result is emitted.

Output

SwitchOnNext

Useful if you have an observable of observables! Emits items from the first observable until the second observable can start emitting, then unsubscribes from the first and starts emitting from the second.

Output

Zip

Combines observables via a function and emits single items for each combination based on the results of this function. Zip waits for both observables to have emitted before releasing the combined emission.

Output