Why is RxJava 1.x flatMap() operator is implemented with merge?
public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? extends R>> func) {
if (getClass() == ScalarSynchronousObservable.class) {
return ((ScalarSynchronousObservable<T>)this).scalarFlatMap(func);
}
return merge(map(func));
}
From flatMap() call I can return only one Observable that conforms to <? extends Observable<? extends R>>
. Than map(func) call wraps it into another Observable, so that we have something like this Observable<? extends Observable<? extends R>>
. That makes me thinking that merge() call after map(func) is unnecessary.
The merge() operator is said to perform the following:
Flattens an Observable that emits Observables into a single Observable that emits the items emitted by those Observables, without any transformation.
Now inside the flat map we can only have an Observable that emits one Observable. Why merge? What am I missing here?
Thank you.