Class ReduceOperator
Extension methods implementing the reduce operator.
public static class ReduceOperator
- Inheritance
-
System.ObjectReduceOperator
Remarks
Behaves like ScanOperator, except only the final accumulated value is emitted, once
source completes, rather than the running value after every emission. Implemented standalone
(not as Scan(...).Last()) since this port has no Last operator yet.
Methods
Reduce<T>(Observable<T>, Func<T, T, int, T>)
Applies accumulator to each value emitted by source, along with its
zero-based index, emitting only the final accumulated value once source completes.
There is no seed: the first value emitted by source becomes the initial accumulated
state, without ever being passed to accumulator.
public static Observable<T> Reduce<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 that emits the final accumulated value once
sourcecompletes, if it ever emitted.
Type Parameters
TThe type of values emitted by
sourceand of the output.
Remarks
If source completes without ever emitting, the output completes without emitting any
value either (there being no first value to seed with). 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 via OnError.
Reduce<T>(Observable<T>, Func<T, T, T>)
Applies accumulator to each value emitted by source, emitting only
the final accumulated value once source completes. There is no seed: the first value
emitted by source becomes the initial accumulated state, without ever being passed to
accumulator.
public static Observable<T> Reduce<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 that emits the final accumulated value once
sourcecompletes, if it ever emitted.
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.
Reduce<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 only the final accumulated value
once source completes.
public static Observable<TAcc> Reduce<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 that emits the final accumulated value once
sourcecompletes.
Type Parameters
TSourceThe type of values emitted by
source.TAccThe type of the accumulated state and of the output value.
Remarks
If source completes without ever emitting, the final value is seed
itself. If accumulator throws, the exception is forwarded to the subscriber via
OnError instead of propagating synchronously, and no value is ever emitted.
Reduce<TSource, TAcc>(Observable<TSource>, Func<TAcc, TSource, TAcc>, TAcc)
Applies accumulator to seed and each value emitted by
source, emitting only the final accumulated value once source
completes.
public static Observable<TAcc> Reduce<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 that emits the final accumulated value once
sourcecompletes.
Type Parameters
TSourceThe type of values emitted by
source.TAccThe type of the accumulated state and of the output value.
Remarks
Equivalent to the indexed overload with the index ignored. See its remarks for full behavior.