Applies an accumulator function over a view. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Namespace:  C1.LiveLinq
Assembly:  C1.LiveLinq (in C1.LiveLinq.dll)

Syntax

C#
public static AggregationView<TSource, TResult> LiveAggregate<TSource, TAccumulate, TResult>(
	this View<TSource> source,
	TAccumulate seed,
	Expression<Func<TAccumulate, TSource, TAccumulate>> funcAdd,
	Expression<Func<TAccumulate, TSource, TAccumulate>> funcRemove,
	Expression<Func<TAccumulate, TSource, bool>> funcRemoveDefined,
	Expression<Func<TAccumulate, TResult>> resultSelector
)
Visual Basic
<ExtensionAttribute> _
Public Shared Function LiveAggregate(Of TSource, TAccumulate, TResult) ( _
	source As View(Of TSource), _
	seed As TAccumulate, _
	funcAdd As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)), _
	funcRemove As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)), _
	funcRemoveDefined As Expression(Of Func(Of TAccumulate, TSource, Boolean)), _
	resultSelector As Expression(Of Func(Of TAccumulate, TResult)) _
) As AggregationView(Of TSource, TResult)

Parameters

source
Type: C1.LiveLinq.LiveViews..::..View<(Of <(<'TSource>)>)>
A view to aggregate over.
seed
Type: TAccumulate
The initial accumulator value.
funcAdd
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TSource, TAccumulate>)>)>>)>)>
An accumulator function to be invoked on each element that is added to the source view.
funcRemove
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TSource, TAccumulate>)>)>>)>)>
A function to be applied to the accumulated value and to an element to obtain the changed accumulated value, when an element is removed from the source view.
funcRemoveDefined
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TSource, Boolean>)>)>>)>)>
A function used to determine whether funcRemove must be applied when an element is removed from the source view, or the accumulated value is not affected by its removal.
resultSelector
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TResult>)>)>>)>)>
A function to transform the final accumulator value into the result value.

Type Parameters

TSource
The type of the elements of source.
TAccumulate
The type of the accumulator value.
TResult
The type of the resulting value.

Return Value

A view representing the final accumulator value.

Remarks

It is possible to use standard LINQ query operator Aggregate instead of LiveAggregate. Both are "live" in the sense that they are recomputed automatically when any change occurs in the source. The difference is that Aggregate will every time loop through the entire source collection and aggregate it from scratch, whereas LiveAggregate will use a more performant algorithm, will maintain its value incrementally, processing only those source items that actually changed.

See Also