 | GeneratorAggregateTSource, TResult Method (IGeneratorTSource, FuncTResult, TSource, TResult, TResult) |
Makes a generator that generates a running aggregate of the source generator.
Namespace:
Gamelogic.Extensions.Algorithms
Assembly:
Assembly-CSharp (in Assembly-CSharp.dll) Version: 0.0.0.0
Syntaxpublic static IGenerator<TResult> Aggregate<TSource, TResult>(
this IGenerator<TSource> generator,
Func<TResult, TSource, TResult> aggregator,
TResult initialValue
)
Parameters
- generator
- Type: Gamelogic.Extensions.AlgorithmsIGeneratorTSource
The source generator. - aggregator
- Type: SystemFuncTResult, TSource, TResult
The aggregator function. - initialValue
- Type: TResult
The initial value.
Type Parameters
- TSource
- The type of elements of the source generator.
- TResult
- The type of elements to generate.
Return Value
Type:
IGeneratorTResultA new generator.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IGeneratorTSource. 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).
RemarksThe resulting generator will generate the following sequence:
result0 = aggregator(initialValue, generator[0])result1 = aggregator(result0, generator[1])result2 = aggregator(result1, generator[2])
Examples The following will generate the maximum element generated by
source so far:
var generator = source.Aggregate((x, y) = Max(x, y));
For example, if source generates 0 1 2 0 1 2..., then generator will
generate 0 1 2 2 2 2...
See Also