Method Iterate
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
Iterate<TSource>(TSource, Func<TSource, TSource>)
Makes a generator that returns iterations of the specified initial element.
public static IGenerator<TSource> Iterate<TSource>(TSource initialElement, Func<TSource, TSource> iterator)Parameters
- initialElementTSource
- The initial element. 
- iteratorFunc<TSource, TSource>
- The iteration function. 
Returns
- IGenerator<TSource>
- IGenerator<TSource>. 
Type Parameters
- TSource
- The type of the source generator. 
Remarks
If the iteration function is f and the initial element is x, then
the result generator will generate x, f(x), f(f(x)), f(f(f(x))), ...
Exceptions
- ArgumentNullException
- iterator 
Iterate<TSource, TSource2>(TSource, IGenerator<TSource2>, Func<TSource, TSource2, TSource>)
Applies a function on the last element to produce the next element. The function takes twp parameters; the second parameter is supplied by a generator.
public static IGenerator<TSource> Iterate<TSource, TSource2>(TSource initialElement, IGenerator<TSource2> parm2, Func<TSource, TSource2, TSource> iterator)Parameters
- initialElementTSource
- parm2IGenerator<TSource2>
- iteratorFunc<TSource, TSource2, TSource>
Returns
- IGenerator<TSource>
Type Parameters
- TSource
- TSource2
Iterate<TSource>(TSource, TSource, Func<TSource, TSource, TSource>)
Makes a generator that uses an iterator function to generate elements.
public static IGenerator<TSource> Iterate<TSource>(TSource initialElement0, TSource initialElement1, Func<TSource, TSource, TSource> iterator)Parameters
- initialElement0TSource
- The first element to generate. 
- initialElement1TSource
- The second element to generate. 
- iteratorFunc<TSource, TSource, TSource>
- The iterator function. 
Returns
- IGenerator<TSource>
Type Parameters
- TSource
- The type of the t source. 
Remarks
The iterator function is applied the last two items generated to produce the next one. The first two elements are provided by the caller. For example,
Iterate(0, 1, (x, y) => x + y);Exceptions
- ArgumentNullException
- iterator 
Iterate<TSource>(TSource, TSource, TSource, Func<TSource, TSource, TSource, TSource>)
Makes a generator that uses an iterator function to generate elements.
public static IGenerator<TSource> Iterate<TSource>(TSource initialElement0, TSource initialElement1, TSource initialElement2, Func<TSource, TSource, TSource, TSource> iterator)Parameters
- initialElement0TSource
- The first element to generate. 
- initialElement1TSource
- The second element to generate. 
- initialElement2TSource
- The third element to generate. 
- iteratorFunc<TSource, TSource, TSource, TSource>
- The iterator function. 
Returns
- IGenerator<TSource>
Type Parameters
- TSource
- The type of the t source. 
Remarks
The iterator function is applied the last three items generated to produce the next one. The first three elements are provided by the caller. For example,
Iterate(0, 0, 1, (x, y, z) => x + y + z);Exceptions
- ArgumentNullException
- iterator 
Iterate<TSource>(TSource, TSource, TSource, TSource, Func<TSource, TSource, TSource, TSource, TSource>)
Makes a generator that uses an iterator function to generate elements.
public static IGenerator<TSource> Iterate<TSource>(TSource initialElement0, TSource initialElement1, TSource initialElement2, TSource initialElement3, Func<TSource, TSource, TSource, TSource, TSource> iterator)Parameters
- initialElement0TSource
- The first element to generate. 
- initialElement1TSource
- The second element to generate. 
- initialElement2TSource
- The third element to generate. 
- initialElement3TSource
- The fourth element to generate. 
- iteratorFunc<TSource, TSource, TSource, TSource, TSource>
- The iterator function. 
Returns
- IGenerator<TSource>
Type Parameters
- TSource
- The type of the t source. 
Remarks
The iterator function is applied the last four items generated to produce the next one. The first four elements are provided by the caller. For example,
Iterate(0, 0, 0, 1, (x, y, z, w) => x + y + w + z);Exceptions
- ArgumentNullException
- iterator 
Iterate<TSource>(IEnumerable<TSource>, Func<IList<TSource>, TSource>)
Makes a generator that uses an iterator function to generate elements.
public static IGenerator<TSource> Iterate<TSource>(IEnumerable<TSource> initialElements, Func<IList<TSource>, TSource> iterator)Parameters
- initialElementsIEnumerable<TSource>
- The initial elements. 
- iteratorFunc<IList<TSource>, TSource>
- The iterator function. 
Returns
- IGenerator<TSource>
Type Parameters
- TSource
- The type of elements to generate. 
Remarks
Uses the last n elements to generate the next one, where n is the same number of elements as is provided initially.
Exceptions
- ArgumentNullException
- iterator