switchMap

fun <T, R> Observable<T>.switchMap(func: (T) -> Observable<R>): Observable<R>

Returns a new Observable by applying a function that you supply to each item emitted by the source Observable that returns an Observable, and then emitting the items emitted by the most recently emitted of these Observables.

The resulting Observable completes if both the upstream Observable and the last inner Observable, if any, complete. If the upstream Observable signals an onError, the inner Observable is unsubscribed and the error delivered in-sequence.

Return

an Observable that emits the items emitted by the Observable returned from applying func to the most recently emitted item emitted by the source Observable

Parameters

R

the element type of the inner Observables and the output

func

a function that, when applied to an item emitted by the source Observable, returns an Observable

See also