/// <summary> /// Projects each element in a generator to a new form. /// </summary> /// <typeparam name="T">The type of the generator's value.</typeparam> /// <typeparam name="TResult">The type of the resultant generator's value.</typeparam> /// <param name="gen">The generator to apply the projection to.</param> /// <param name="selector">A projection function to apply to each value.</param> /// <returns>A new generator with the projection applied.</returns> /// <summary> /// Projects each element in a generator to a new form. /// </summary> /// <typeparam name="T">The type of the generator's value.</typeparam> /// <typeparam name="TResult">The type of the resultant generator's value.</typeparam> /// <param name="gen">The generator to apply the projection to.</param> /// <param name="selector">A projection function to apply to each value.</param> /// <returns>A new generator with the projection applied.</returns> public static IGen <TResult> Select <T, TResult>(this IGen <T> gen, Func <T, TResult> selector) { GenInstanceTransformation <T, TResult> transformation = (instance) => { var sourceExampleSpace = instance.ExampleSpace; var projectedExampleSpace = instance.ExampleSpace.Map(selector); return(GenIterationFactory.Instance( instance.ReplayParameters, instance.NextParameters, projectedExampleSpace, instance.ExampleSpaceHistory)); }; return(gen.TransformInstances(transformation)); }
public static IGen <T> Unfold <T>( this IGen <T> gen, Func <T, IExampleSpace <T> > unfolder) { GenInstanceTransformation <T, T> transformation = (instance) => { return(GenIterationFactory.Instance( instance.ReplayParameters, instance.NextParameters, unfolder(instance.ExampleSpace.Current.Value), instance.ExampleSpaceHistory)); }; return(gen.TransformInstances(transformation)); }
public static IGen <T> NoShrink <T>(this IGen <T> gen) => gen.TransformInstances(instance => GenIterationFactory.Instance( instance.ReplayParameters, instance.NextParameters, ExampleSpaceFactory.Singleton(instance.ExampleSpace.Current.Id, instance.ExampleSpace.Current.Value), instance.ExampleSpaceHistory));