ObservableExtensions.

Reduce<TSource, TAccumulate, TResult>(IObservable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>) Method

Summary

Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value, and the specified result selector function is used to select the result value.

Syntax

public static IObservable<TResult> Reduce<TSource, TAccumulate, TResult>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector)

Remarks

The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.

Type Parameters

Name Description
TSource The type of the elements in the source sequence.
TAccumulate The type of the accumulator value.
TResult The type of the resulting value.

Parameters

Name Type Description
source IObservable<TSource> An observable sequence to aggregate over.
seed TAccumulate The initial accumulator value.
accumulator Func<TAccumulate, TSource, TAccumulate> An accumulator function to be invoked on each element.
resultSelector Func<TAccumulate, TResult> A function to transform the final accumulator value into the result value.

Return Value

Type Description
IObservable<TResult> An observable sequence containing a single element with the final accumulator value.