flatMap

fun <T, O> ObservableSet<T>.flatMap(transformer: (T) -> Observable<O>): Observable<Option<O>>

Transforms an ObservableSet of type T into a single Observable of type arrow.core.Option<O> by fusing the individual observables obtained from each item in the set.

The emissions are merged, as in the flatMap operator of the ReactiveX convention: the result emits the value of whichever mapped observable emitted, and the current value of the observables of elements joining the set. Observables of elements leaving the set are unsubscribed. Merging has no single current value: Observable.current is the current value of the observable of the first element of the set. To follow only the observable selected by the latest value, use Observables.switchMap instead.

The resulting observable is total:

  • If the set is empty, it emits (and its Observable.current is) arrow.core.None

  • If the set is non-empty, it emits arrow.core.Some values coming from any mapped observable

Return

An Observable of type arrow.core.Option<O> that is safe to use on empty sets.

Parameters

transformer

A function that maps each element of the source ObservableSet to an Observable of type O.

Type Parameters

T

The type of elements in the ObservableSet.

O

The type of the resulting fused observable.