Table of Contents

Class SwitchScanOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Extension methods implementing the switchScan operator.

public static class SwitchScanOperator
Inheritance
System.Object
SwitchScanOperator

Methods

SwitchScan<TSource, TAcc>(Observable<TSource>, Func<TAcc, TSource, Observable<TAcc>>, TAcc)

Applies accumulator to each value emitted by source, subscribing to the inner observable it returns and mirroring only the most recently returned one. The last value produced by an inner observable becomes the new accumulated state, passed as acc to the next call of accumulator.

public static Observable<TAcc> SwitchScan<TSource, TAcc>(this Observable<TSource> source, Func<TAcc, TSource, Observable<TAcc>> accumulator, TAcc seed)

Parameters

source Observable<TSource>

The source sequence.

accumulator Func<TAcc, TSource, Observable<TAcc>>

A function called with the current accumulated state and the source value; returns an inner observable to switch to, whose values become the new accumulated state.

seed TAcc

The initial accumulated state, used for the first call to accumulator.

Returns

Observable<TAcc>

An observable of the values produced by only the most recently switched-to inner observable.

Type Parameters

TSource

The type of values emitted by source.

TAcc

The type of the accumulated state, of the values emitted by the inner observables, and of the output.

SwitchScan<TSource, TAcc>(Observable<TSource>, Func<TAcc, TSource, int, Observable<TAcc>>, TAcc)

Applies accumulator to each value emitted by source, along with its zero-based index, subscribing to the inner observable it returns and mirroring only the most recently returned one — like SwitchMapOperator, the previous inner observable's subscription is torn down (even if still live) before subscribing to the new one. The last value produced by an inner observable becomes the new accumulated state, passed as acc to the next call of accumulator. The output completes once source has completed and the current inner observable, if any, has also completed.

public static Observable<TAcc> SwitchScan<TSource, TAcc>(this Observable<TSource> source, Func<TAcc, TSource, int, Observable<TAcc>> accumulator, TAcc seed)

Parameters

source Observable<TSource>

The source sequence.

accumulator Func<TAcc, TSource, int, Observable<TAcc>>

A function called with the current accumulated state, the source value, and its index (starting at 0); returns an inner observable to switch to, whose values become the new accumulated state.

seed TAcc

The initial accumulated state, used for the first call to accumulator.

Returns

Observable<TAcc>

An observable of the values produced by only the most recently switched-to inner observable.

Type Parameters

TSource

The type of values emitted by source.

TAcc

The type of the accumulated state, of the values emitted by the inner observables, and of the output.

Remarks

This is MergeScanOperator combined with SwitchMapOperator's switch-instead-of-merge behavior. If accumulator 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.