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
source1IGenerator<T1>The first generator.
source2IGenerator<T2>The second generator.
resultSelectorFunc<T1, T2, TResult>The result selector function.
Returns
- IGenerator<TResult>
A new generator
Type Parameters
T1The type of elements of the first generator.
T2The type of elements of the second generator.
TResultThe 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
generator1is null.- ArgumentNullException
generator2is null.- ArgumentNullException
resultSelectoris 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
source1IGenerator<T1>The first generator.
source2IGenerator<T2>The second generator.
source3IGenerator<T3>The third generator.
resultSelectorFunc<T1, T2, T3, TResult>The result selector function.
Returns
- IGenerator<TResult>
A new generator
Type Parameters
T1The type of elements of the first generator.
T2The type of elements of the second generator.
T3The type of elements of the third generator.
TResultThe type of the elements of the result generator.
Exceptions
- ArgumentNullException
generator1is null.- ArgumentNullException
generator2is null.- ArgumentNullException
generator3is null.- ArgumentNullException
resultSelectoris 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
source1IGenerator<T1>The first generator.
source2IGenerator<T2>The second generator.
source3IGenerator<T3>The third generator.
source4IGenerator<T4>The fourth generator.
resultSelectorFunc<T1, T2, T3, T4, TResult>The result selector function.
Returns
- IGenerator<TResult>
A new generator
Type Parameters
T1The type of elements of the first generator.
T2The type of elements of the second generator.
T3The type of elements of the third generator.
T4The type of elements of the fourth generator.
TResultThe type of the elements of the result generator.
Exceptions
- ArgumentNullException
generator1is null.- ArgumentNullException
generator2is null.- ArgumentNullException
generator3is null.- ArgumentNullException
generator4is null.- ArgumentNullException
resultSelectoris 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
sourcesIEnumerable<IGenerator<TSource>>The generators.
resultSelectorFunc<IList<TSource>, TResult>The result selector.
Returns
- IGenerator<TResult>
A new generator.
Type Parameters
TSourceThe type of elements of the source generators.
TResultThe type of elements this generator will generate.
Exceptions
- ArgumentNullException
generators
- ArgumentException
Cannot contain null elements;generators