Class ScanOperator
Extension methods implementing the scan operator.
public static class ScanOperator
- Inheritance
-
System.ObjectScanOperator
Remarks
Unlike MergeScanOperator, scan's accumulator returns a plain value synchronously
instead of an inner observable, so every accumulation happens inline with no concurrency to manage.
Methods
Scan<T>(Observable<T>, Func<T, T, int, T>)
Applies accumulator to each value emitted by source, along with
its zero-based index, emitting the updated accumulator value after every source emission after the
first. There is no seed: the first value emitted by source becomes the initial
accumulated state and is emitted as-is, without ever being passed to accumulator.
public static Observable<T> Scan<T>(this Observable<T> source, Func<T, T, int, T> accumulator)
Parameters
sourceObservable<T>The source sequence.
accumulatorFunc<T, T, int, T>A function called with the current accumulated state, the source value, and its index (starting at 1, since index 0 is consumed as the seed); returns the new accumulated state.
Returns
- Observable<T>
An observable of the running accumulator value after each source emission but the first.
Type Parameters
TThe type of values emitted by
sourceand of the output.
Remarks
Because the first value is used directly as the seed, accumulator is first called
(with index 1) on the second source value, not the first. If accumulator
throws, the exception is forwarded to the subscriber via OnError instead of propagating
synchronously. If source completes without ever emitting, the output simply
completes without ever emitting either (there being no first value to seed with).
Scan<T>(Observable<T>, Func<T, T, T>)
Applies accumulator to each value emitted by source, emitting the
updated accumulator value after every source emission after the first. There is no seed: the first value
emitted by source becomes the initial accumulated state and is emitted as-is, without
ever being passed to accumulator.
public static Observable<T> Scan<T>(this Observable<T> source, Func<T, T, T> accumulator)
Parameters
sourceObservable<T>The source sequence.
accumulatorFunc<T, T, T>A function called with the current accumulated state and the source value; returns the new accumulated state.
Returns
- Observable<T>
An observable of the running accumulator value after each source emission but the first.
Type Parameters
TThe type of values emitted by
sourceand of the output.
Remarks
Equivalent to the indexed overload with the index ignored. See its remarks for full behavior.
Scan<TSource, TAcc>(Observable<TSource>, Func<TAcc, TSource, int, TAcc>, TAcc)
Applies accumulator to seed and each value emitted by
source, along with its zero-based index, emitting the updated accumulator value after
every source emission.
public static Observable<TAcc> Scan<TSource, TAcc>(this Observable<TSource> source, Func<TAcc, TSource, int, TAcc> accumulator, TAcc seed)
Parameters
sourceObservable<TSource>The source sequence.
accumulatorFunc<TAcc, TSource, int, TAcc>A function called with the current accumulated state, the source value, and its index (starting at 0); returns the new accumulated state.
seedTAccThe initial accumulated state.
Returns
- Observable<TAcc>
An observable of the running accumulator value after each source emission.
Type Parameters
TSourceThe type of values emitted by
source.TAccThe type of the accumulated state and of the output values.
Remarks
If accumulator throws, the exception is forwarded to the subscriber via OnError
instead of propagating synchronously.
Scan<TSource, TAcc>(Observable<TSource>, Func<TAcc, TSource, TAcc>, TAcc)
Applies accumulator to seed and each value emitted by
source, emitting the updated accumulator value after every source emission.
public static Observable<TAcc> Scan<TSource, TAcc>(this Observable<TSource> source, Func<TAcc, TSource, TAcc> accumulator, TAcc seed)
Parameters
sourceObservable<TSource>The source sequence.
accumulatorFunc<TAcc, TSource, TAcc>A function called with the current accumulated state and the source value; returns the new accumulated state.
seedTAccThe initial accumulated state.
Returns
- Observable<TAcc>
An observable of the running accumulator value after each source emission.
Type Parameters
TSourceThe type of values emitted by
source.TAccThe type of the accumulated state and of the output values.
Remarks
Equivalent to the indexed overload with the index ignored. See its remarks for full behavior.