Skip to content

M_CodeJam_Collections_EnumerableExtensions_AggregateOrDefault__2

Andrew Koryavchenko edited this page Jul 4, 2017 · 5 revisions

EnumerableExtensions.AggregateOrDefault(TSource, TAccumulate) Method (IEnumerable(TSource), TAccumulate, Func(TAccumulate, TSource, TAccumulate), Func(TAccumulate))

Applies an accumulator function over a sequence.

Namespace: CodeJam.Collections
Assembly: CodeJam (in CodeJam.dll) Version: 1.1.0.0 (1.1.0.0)

Syntax

C#

public static TAccumulate AggregateOrDefault<TSource, TAccumulate>(
	this IEnumerable<TSource> source,
	TAccumulate seed,
	Func<TAccumulate, TSource, TAccumulate> func,
	Func<TAccumulate> defaultSelector
)

VB

<ExtensionAttribute>
Public Shared Function AggregateOrDefault(Of TSource, TAccumulate) ( 
	source As IEnumerable(Of TSource),
	seed As TAccumulate,
	func As Func(Of TAccumulate, TSource, TAccumulate),
	defaultSelector As Func(Of TAccumulate)
) As TAccumulate

F#

[<ExtensionAttribute>]
static member AggregateOrDefault : 
        source : IEnumerable<'TSource> * 
        seed : 'TAccumulate * 
        func : Func<'TAccumulate, 'TSource, 'TAccumulate> * 
        defaultSelector : Func<'TAccumulate> -> 'TAccumulate 

Parameters

 

source
Type: System.Collections.Generic.IEnumerable(TSource)
An IEnumerable(T) to aggregate over.
seed
Type: TAccumulate
The initial accumulator value.
func
Type: System.Func(TAccumulate, TSource, TAccumulate)
An accumulator function to be invoked on each element.
defaultSelector
Type: System.Func(TAccumulate)
A function to select default value if the source is empty.

Type Parameters

 

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

Return Value

Type: TAccumulate
The final accumulator value.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(TSource). When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also

Reference

EnumerableExtensions Class
AggregateOrDefault Overload
CodeJam.Collections Namespace

Clone this wiki locally