Method Aggregate
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
Aggregate<TSource, TResult>(IGenerator<TSource>, Func<TResult, TSource, TResult>, TResult)
Makes a generator that generates a running aggregate of the source generator.
public static IGenerator<TResult> Aggregate<TSource, TResult>(this IGenerator<TSource> generator, Func<TResult, TSource, TResult> aggregator, TResult initialValue)
Parameters
generatorIGenerator<TSource>The source generator.
aggregatorFunc<TResult, TSource, TResult>The aggregator function.
initialValueTResultThe initial value.
Returns
- IGenerator<TResult>
A new generator.
Type Parameters
TSourceThe type of elements of the source generator.
TResultThe type of elements to generate.
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...
Remarks
The resulting generator will generate the following sequence:
result0 = aggregator(initialValue, generator[0])result1 = aggregator(result0, generator[1])result2 = aggregator(result1, generator[2])
Aggregate<TSource>(IGenerator<TSource>, Func<TSource, TSource, TSource>, TSource)
Makes a generator that generates a running aggregate of the source generator.
public static IGenerator<TSource> Aggregate<TSource>(this IGenerator<TSource> generator, Func<TSource, TSource, TSource> aggregator, TSource initialValue)
Parameters
generatorIGenerator<TSource>The source generator.
aggregatorFunc<TSource, TSource, TSource>The aggregator.
initialValueTSourceThe initial value.
Returns
- IGenerator<TSource>
A new generator.
Type Parameters
TSourceThe type of elements of the source generator.
Remarks
The resulting generator will generate the following sequence:
result0 = aggregator(initialValue, generator[0])result1 = aggregator(result0, generator[1])result2 = aggregator(result1, generator[2])
Aggregate<TSource>(IGenerator<TSource>, Func<TSource, TSource, TSource>)
Makes a generator that generates a running aggregate of the source generator.
public static IGenerator<TSource> Aggregate<TSource>(this IGenerator<TSource> generator, Func<TSource, TSource, TSource> aggregator)
Parameters
generatorIGenerator<TSource>The source generator.
aggregatorFunc<TSource, TSource, TSource>The aggregator.
Returns
- IGenerator<TSource>
A new generator.
Type Parameters
TSourceThe type of elements of the source generator.
Remarks
This overload uses the first item as the first element to generate.
The resulting generator will generate the following sequence:
result0 = generator[0]result1 = aggregator(result0, generator[1])result2 = aggregator(result1, generator[2])
Exceptions
- ArgumentNullException
generatoris null.- ArgumentNullException
aggregatoris null.