Method Combine
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
Combine<T1, T2, TResult>(IGenerator<T1>, IGenerator<T2>, Func<T1, T2, TResult>)
Combines the specified generators by applying a result selector function to the elements of each generator.
public static IGenerator<TResult> Combine<T1, T2, TResult>(IGenerator<T1> source1, IGenerator<T2> source2, Func<T1, T2, TResult> resultSelector)
Parameters
source1
IGenerator<T1>The first generator.
source2
IGenerator<T2>The second generator.
resultSelector
Func<T1, T2, TResult>The result selector function.
Returns
- IGenerator<TResult>
A new generator
Type Parameters
T1
The type of elements of the first generator.
T2
The type of elements of the second generator.
TResult
The type of the elements of the result generator.
Examples
The following will code will add the elements of two generators to form its elements.
var generator1 = Generator.Count(3); //generates 0 1 2 0 1 2 0 1 2...
var generator2 = Generator.Count(2); //generates 0 1 0 1 0 1 0 1 0...
var generator = Generator.Combine(generator1, generator2, (x, y) => x + y);
//generates 0 2 2 1 1 3 0 2 2...</code></pre>
Exceptions
- ArgumentNullException
generator1 or generator2 or resultSelector
- ArgumentNullException
generator1
is null.- ArgumentNullException
generator2
is null.- ArgumentNullException
resultSelector
is null.
Combine<T1, T2, T3, TResult>(IGenerator<T1>, IGenerator<T2>, IGenerator<T3>, Func<T1, T2, T3, TResult>)
Combines the specified generators by applying a result selector function to the elements of each generator.
public static IGenerator<TResult> Combine<T1, T2, T3, TResult>(IGenerator<T1> source1, IGenerator<T2> source2, IGenerator<T3> source3, Func<T1, T2, T3, TResult> resultSelector)
Parameters
source1
IGenerator<T1>The first generator.
source2
IGenerator<T2>The second generator.
source3
IGenerator<T3>The third generator.
resultSelector
Func<T1, T2, T3, TResult>The result selector function.
Returns
- IGenerator<TResult>
A new generator
Type Parameters
T1
The type of elements of the first generator.
T2
The type of elements of the second generator.
T3
The type of elements of the third generator.
TResult
The type of the elements of the result generator.
Exceptions
- ArgumentNullException
generator1
is null.- ArgumentNullException
generator2
is null.- ArgumentNullException
generator3
is null.- ArgumentNullException
resultSelector
is null.
Combine<T1, T2, T3, T4, TResult>(IGenerator<T1>, IGenerator<T2>, IGenerator<T3>, IGenerator<T4>, Func<T1, T2, T3, T4, TResult>)
Combines the specified generators by applying a result selector function to the elements of each generator.
public static IGenerator<TResult> Combine<T1, T2, T3, T4, TResult>(IGenerator<T1> source1, IGenerator<T2> source2, IGenerator<T3> source3, IGenerator<T4> source4, Func<T1, T2, T3, T4, TResult> resultSelector)
Parameters
source1
IGenerator<T1>The first generator.
source2
IGenerator<T2>The second generator.
source3
IGenerator<T3>The third generator.
source4
IGenerator<T4>The fourth generator.
resultSelector
Func<T1, T2, T3, T4, TResult>The result selector function.
Returns
- IGenerator<TResult>
A new generator
Type Parameters
T1
The type of elements of the first generator.
T2
The type of elements of the second generator.
T3
The type of elements of the third generator.
T4
The type of elements of the fourth generator.
TResult
The type of the elements of the result generator.
Exceptions
- ArgumentNullException
generator1
is null.- ArgumentNullException
generator2
is null.- ArgumentNullException
generator3
is null.- ArgumentNullException
generator4
is null.- ArgumentNullException
resultSelector
is null.
Combine<TSource, TResult>(IEnumerable<IGenerator<TSource>>, Func<IList<TSource>, TResult>)
Makes a generator that combines the elements of specified generators.
public static IGenerator<TResult> Combine<TSource, TResult>(IEnumerable<IGenerator<TSource>> sources, Func<IList<TSource>, TResult> resultSelector)
Parameters
sources
IEnumerable<IGenerator<TSource>>The generators.
resultSelector
Func<IList<TSource>, TResult>The result selector.
Returns
- IGenerator<TResult>
A new generator.
Type Parameters
TSource
The type of elements of the source generators.
TResult
The type of elements this generator will generate.
Exceptions
- ArgumentNullException
generators
- ArgumentException
Cannot contain null elements;generators