Method Apply
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
Apply<TSource>(IGenerator<TSource>, Action<TSource>)
Makes a generator that applies an Action<T> on the elements it generates.
public static IGenerator<TSource> Apply<TSource>(this IGenerator<TSource> source, Action<TSource> action)
Parameters
source
IGenerator<TSource>The source generator.
action
Action<TSource>The action to apply to generated elements.
Returns
- IGenerator<TSource>
A new generator.
Type Parameters
TSource
The type of the elements to generate.
Examples
The following will generate a generator that generates 0 1 2 3 0 1 2 ... and print the values to the console.
var generator = Generator.Count(4).Apply((x) => {Debug.Log(x);});
The following will generate a monster, and sets its properties based on the player's current level:
var monsterGenerator = Generator
.Constant(monsterTemplate)
.Apply(m => m.SetProperties(GetPlayerLevel());
Exceptions
- ArgumentNullException
generator
is $(null).- ArgumentNullException
action
is $(null).