Skip to content

,--1,System.Func{--1,--0,--1})} ,--1,System.Func{--1,--0,--1},System.Func{--1,--2})} ,System.Func{--0,--0,--0})}

Observable.Aggregate(IObservable, TAccumulate, Func) method

Defined in

Type: Observable Namespace: System.Reactive.Linq Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static IObservable<TAccumulate> Aggregate<TSource, TAccumulate>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
  • 2. public static IObservable<TResult> Aggregate<TSource, TAccumulate, TResult>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector)
  • 3. public static IObservable<TSource> Aggregate<TSource>(this IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator)

1. Overload

public static IObservable<TAccumulate> Aggregate<TSource, TAccumulate>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)

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. For aggregation behavior with incremental intermediate results, see Scan.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.
TAccumulateThe type of the result of the aggregation.

Parameters

NameTypeDescription
sourceIObservableAn observable sequence to aggregate over.
seedTAccumulateThe initial accumulator value.
accumulatorFuncAn accumulator function to be invoked on each element.

Returns: IObservable -- An observable sequence containing a single element with the final accumulator value.

Remarks

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

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or accumulator is null.

2. Overload

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

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.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.
TAccumulateThe type of the accumulator value.
TResultThe type of the resulting value.

Parameters

NameTypeDescription
sourceIObservableAn observable sequence to aggregate over.
seedTAccumulateThe initial accumulator value.
accumulatorFuncAn accumulator function to be invoked on each element.
resultSelectorFuncA function to transform the final accumulator value into the result value.

Returns: IObservable -- An observable sequence containing a single element with the final accumulator value.

Remarks

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

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or accumulator or resultSelector is null.

3. Overload

public static IObservable<TSource> Aggregate<TSource>(this IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator)

Summary: Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. For aggregation behavior with incremental intermediate results, see Scan.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence and the result of the aggregation.

Parameters

NameTypeDescription
sourceIObservableAn observable sequence to aggregate over.
accumulatorFuncAn accumulator function to be invoked on each element.

Returns: IObservable -- An observable sequence containing a single element with the final accumulator value.

Remarks

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

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or accumulator is null.
System.InvalidOperationException(Asynchronous) The source sequence is empty.