# C1.LiveLinq.LiveViewExtensions.LiveAggregate

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate_" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate*">LiveAggregate Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_LiveLinq_LiveViewExtensions_LiveAggregate_" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate*"></a>
<h4 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate__1_C1_LiveLinq_LiveViews_View___0__System_Linq_Expressions_Expression_System_Func___0___0___0___System_Linq_Expressions_Expression_System_Func___0___0___0___System_Linq_Expressions_Expression_System_Func___0___0_System_Boolean___" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate``1(C1.LiveLinq.LiveViews.View{``0},System.Linq.Expressions.Expression{System.Func{``0,``0,``0}},System.Linq.Expressions.Expression{System.Func{``0,``0,``0}},System.Linq.Expressions.Expression{System.Func{``0,``0,System.Boolean}})">LiveAggregate&lt;TSource&gt;(View&lt;TSource&gt;, Expression&lt;Func&lt;TSource, TSource, TSource&gt;&gt;, Expression&lt;Func&lt;TSource, TSource, TSource&gt;&gt;, Expression&lt;Func&lt;TSource, TSource, bool&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>Applies an accumulator function over a view.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static AggregationView&lt;TSource, TSource&gt; LiveAggregate&lt;TSource&gt;(this View&lt;TSource&gt; source, Expression&lt;Func&lt;TSource, TSource, TSource&gt;&gt; funcAdd, Expression&lt;Func&lt;TSource, TSource, TSource&gt;&gt; funcRemove, Expression&lt;Func&lt;TSource, TSource, bool&gt;&gt; funcRemoveDefined)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function LiveAggregate(Of TSource)(source As View(Of TSource), funcAdd As Expression(Of Func(Of TSource, TSource, TSource)), funcRemove As Expression(Of Func(Of TSource, TSource, TSource)), funcRemoveDefined As Expression(Of Func(Of TSource, TSource, Boolean))) As AggregationView(Of TSource, TSource)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;TSource&gt;</td>
      <td><span class="parametername">source</span></td>
      <td><p>A view to aggregate over.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TSource, TSource, TSource&gt;&gt;</td>
      <td><span class="parametername">funcAdd</span></td>
      <td><p>An accumulator function to be invoked on each element that is added to the source view.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TSource, TSource, TSource&gt;&gt;</td>
      <td><span class="parametername">funcRemove</span></td>
      <td><p>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.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TSource, TSource, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>&gt;&gt;</td>
      <td><span class="parametername">funcRemoveDefined</span></td>
      <td><p>A function used to determine whether <i>funcRemove</i> must be applied when an element
is removed from the source view, or the accumulated value is not affected by its removal.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;TSource, TSource&gt;</td>
      <td><p>A view representing the final accumulator value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">TSource</span></td>
      <td><p>The type of the elements of <i>source.</i></p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate__1_C1_LiveLinq_LiveViews_View___0__System_Linq_Expressions_Expression_System_Func___0___0___0___System_Linq_Expressions_Expression_System_Func___0___0___0___System_Linq_Expressions_Expression_System_Func___0___0_System_Boolean____remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>It is possible to use standard LINQ query operator <b>Aggregate</b> instead of <b>LiveAggregate</b>.
Both are &quot;live&quot; in the sense that they are recomputed automatically when any change occurs in the source.
The difference is that <b>Aggregate</b> will every time loop through the entire source collection and aggregate it from scratch,
whereas <b>LiveAggregate</b> will use a more performant algorithm, will maintain its value incrementally,
processing only those source items that actually changed.</p>
</div>


<a id="C1_LiveLinq_LiveViewExtensions_LiveAggregate_" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate*"></a>
<h4 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate__2_C1_LiveLinq_LiveViews_View___0____1_System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0_System_Boolean___" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate``2(C1.LiveLinq.LiveViews.View{``0},``1,System.Linq.Expressions.Expression{System.Func{``1,``0,``1}},System.Linq.Expressions.Expression{System.Func{``1,``0,``1}},System.Linq.Expressions.Expression{System.Func{``1,``0,System.Boolean}})">LiveAggregate&lt;TSource, TAccumulate&gt;(View&lt;TSource&gt;, TAccumulate, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt;, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt;, Expression&lt;Func&lt;TAccumulate, TSource, bool&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>Applies an accumulator function over a view. The specified seed value is used as the initial accumulator value.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static AggregationView&lt;TSource, TAccumulate&gt; LiveAggregate&lt;TSource, TAccumulate&gt;(this View&lt;TSource&gt; source, TAccumulate seed, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt; funcAdd, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt; funcRemove, Expression&lt;Func&lt;TAccumulate, TSource, bool&gt;&gt; funcRemoveDefined)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function LiveAggregate(Of TSource, TAccumulate)(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))) As AggregationView(Of TSource, TAccumulate)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;TSource&gt;</td>
      <td><span class="parametername">source</span></td>
      <td><p>A view to aggregate over.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">TAccumulate</span></td>
      <td><span class="parametername">seed</span></td>
      <td><p>The initial accumulator value.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TAccumulate, TSource, TAccumulate&gt;&gt;</td>
      <td><span class="parametername">funcAdd</span></td>
      <td><p>An accumulator function to be invoked on each element that is added to the source view.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TAccumulate, TSource, TAccumulate&gt;&gt;</td>
      <td><span class="parametername">funcRemove</span></td>
      <td><p>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.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TAccumulate, TSource, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>&gt;&gt;</td>
      <td><span class="parametername">funcRemoveDefined</span></td>
      <td><p>A function used to determine whether <i>funcRemove</i> must be applied when an element
is removed from the source view, or the accumulated value is not affected by its removal.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;TSource, TAccumulate&gt;</td>
      <td><p>A view representing the final accumulator value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">TSource</span></td>
      <td><p>The type of the elements of <i>source.</i></p>
</td>
    </tr>
    <tr>
      <td><span class="parametername">TAccumulate</span></td>
      <td><p>The type of the accumulator value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate__2_C1_LiveLinq_LiveViews_View___0____1_System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0_System_Boolean____remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>It is possible to use standard LINQ query operator <b>Aggregate</b> instead of <b>LiveAggregate</b>.
Both are &quot;live&quot; in the sense that they are recomputed automatically when any change occurs in the source.
The difference is that <b>Aggregate</b> will every time loop through the entire source collection and aggregate it from scratch,
whereas <b>LiveAggregate</b> will use a more performant algorithm, will maintain its value incrementally,
processing only those source items that actually changed.</p>
</div>


<a id="C1_LiveLinq_LiveViewExtensions_LiveAggregate_" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate*"></a>
<h4 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate__3_C1_LiveLinq_LiveViews_View___0____1_System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0_System_Boolean___System_Linq_Expressions_Expression_System_Func___1___2___" data-uid="C1.LiveLinq.LiveViewExtensions.LiveAggregate``3(C1.LiveLinq.LiveViews.View{``0},``1,System.Linq.Expressions.Expression{System.Func{``1,``0,``1}},System.Linq.Expressions.Expression{System.Func{``1,``0,``1}},System.Linq.Expressions.Expression{System.Func{``1,``0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``1,``2}})">LiveAggregate&lt;TSource, TAccumulate, TResult&gt;(View&lt;TSource&gt;, TAccumulate, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt;, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt;, Expression&lt;Func&lt;TAccumulate, TSource, bool&gt;&gt;, Expression&lt;Func&lt;TAccumulate, TResult&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>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.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static AggregationView&lt;TSource, TResult&gt; LiveAggregate&lt;TSource, TAccumulate, TResult&gt;(this View&lt;TSource&gt; source, TAccumulate seed, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt; funcAdd, Expression&lt;Func&lt;TAccumulate, TSource, TAccumulate&gt;&gt; funcRemove, Expression&lt;Func&lt;TAccumulate, TSource, bool&gt;&gt; funcRemoveDefined, Expression&lt;Func&lt;TAccumulate, TResult&gt;&gt; resultSelector)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">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)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;TSource&gt;</td>
      <td><span class="parametername">source</span></td>
      <td><p>A view to aggregate over.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">TAccumulate</span></td>
      <td><span class="parametername">seed</span></td>
      <td><p>The initial accumulator value.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TAccumulate, TSource, TAccumulate&gt;&gt;</td>
      <td><span class="parametername">funcAdd</span></td>
      <td><p>An accumulator function to be invoked on each element that is added to the source view.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TAccumulate, TSource, TAccumulate&gt;&gt;</td>
      <td><span class="parametername">funcRemove</span></td>
      <td><p>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.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-3">Func</a>&lt;TAccumulate, TSource, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>&gt;&gt;</td>
      <td><span class="parametername">funcRemoveDefined</span></td>
      <td><p>A function used to determine whether <i>funcRemove</i> must be applied when an element
is removed from the source view, or the accumulated value is not affected by its removal.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;TAccumulate, TResult&gt;&gt;</td>
      <td><span class="parametername">resultSelector</span></td>
      <td><p>A function to transform the final accumulator value into the result value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;TSource, TResult&gt;</td>
      <td><p>A view representing the final accumulator value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">TSource</span></td>
      <td><p>The type of the elements of <i>source.</i></p>
</td>
    </tr>
    <tr>
      <td><span class="parametername">TAccumulate</span></td>
      <td><p>The type of the accumulator value.</p>
</td>
    </tr>
    <tr>
      <td><span class="parametername">TResult</span></td>
      <td><p>The type of the resulting value.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_LiveLinq_LiveViewExtensions_LiveAggregate__3_C1_LiveLinq_LiveViews_View___0____1_System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0___1___System_Linq_Expressions_Expression_System_Func___1___0_System_Boolean___System_Linq_Expressions_Expression_System_Func___1___2____remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>It is possible to use standard LINQ query operator <b>Aggregate</b> instead of <b>LiveAggregate</b>.
Both are &quot;live&quot; in the sense that they are recomputed automatically when any change occurs in the source.
The difference is that <b>Aggregate</b> will every time loop through the entire source collection and aggregate it from scratch,
whereas <b>LiveAggregate</b> will use a more performant algorithm, will maintain its value incrementally,
processing only those source items that actually changed.</p>
</div>
</div>
