A common task done in ReactiveX is taking two or more Observable<T>
instances and merging them into one Observable<T>
. This merged Observable<T>
will subscribe to all of its merged sources simultaneously, making it effective for merging both finite and infinite Observables. There are a few ways that we can leverage this merging behavior using factories as well as operators.
The Observable.merge()
operator will take two or more Observable<T>
sources emitting the same type T
and then consolidate them into a single Observable<T>
.
If we have only two to four Observable<T>
sources to merge, you can pass each one as an argument to the Observable.merge()
factory. In the following code snippet, I have merged two Observable<String>
instances into one Observable<String>
:
import io.reactivex.Observable; public class Launcher { public static void main(String[] args) { Observable<String> source1...