Table of Contents

Class SwitchMapOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Extension methods implementing the switchMap operator.

public static class SwitchMapOperator
Inheritance
System.Object
SwitchMapOperator

Methods

SwitchMap<TSource, TResult>(Observable<TSource>, Func<TSource, Observable<TResult>>)

Projects each value from source to an inner observable via project and mirrors only the most recently projected inner observable. Whenever source emits a new value, the previous inner observable's subscription is torn down (even if it is still live and emitting) before subscribing to the new one. The output completes once source has completed and the current inner observable, if any, has also completed.

public static Observable<TResult> SwitchMap<TSource, TResult>(this Observable<TSource> source, Func<TSource, Observable<TResult>> project)

Parameters

source Observable<TSource>

The source sequence.

project Func<TSource, Observable<TResult>>

A function that maps each source value to the inner observable to switch to.

Returns

Observable<TResult>

An observable that emits the values of only the most recently projected inner observable.

Type Parameters

TSource

The type of values emitted by source.

TResult

The type of values emitted by the inner observables produced by project.

Remarks

If project throws, the exception is forwarded to the subscriber via OnError instead of propagating synchronously. An error from source or from the active inner observable also terminates the output immediately via OnError.

SwitchMap<TSource, TResult>(Observable<TSource>, Func<TSource, int, Observable<TResult>>)

Projects each value from source, along with its zero-based index, to an inner observable via project and mirrors only the most recently projected inner observable. Whenever source emits a new value, the previous inner observable's subscription is torn down (even if it is still live and emitting) before subscribing to the new one. The output completes once source has completed and the current inner observable, if any, has also completed.

public static Observable<TResult> SwitchMap<TSource, TResult>(this Observable<TSource> source, Func<TSource, int, Observable<TResult>> project)

Parameters

source Observable<TSource>

The source sequence.

project Func<TSource, int, Observable<TResult>>

A function that maps each source value and its index (starting at 0) to the inner observable to switch to.

Returns

Observable<TResult>

An observable that emits the values of only the most recently projected inner observable.

Type Parameters

TSource

The type of values emitted by source.

TResult

The type of values emitted by the inner observables produced by project.

Remarks

If project throws, the exception is forwarded to the subscriber via OnError instead of propagating synchronously. An error from source or from the active inner observable also terminates the output immediately via OnError.