private Terminator <TReduction> EachReducer( TReduction reduction, Func <TReduction, IReducer <TReduction, TInput>, Terminator <TReduction> > func) { return(Reducers.Reduce(Reduction(reduction), Reducer.Make <Terminator <TReduction>, IReducer <TReduction, TInput> >((terminator, reducer) => { terminator = func(terminator.Value, reducer); return Reduction(terminator, terminated: terminator.IsTerminated); })).Value); }
/// <summary> /// Returns a reducer that writes the input to a TextWriter line-by-line. /// </summary> /// <returns>A reducer</returns> public static IReducer <TextWriter, object> WriteLineReducer() => Reducer.Make <TextWriter, object>((writer, input) => { writer.WriteLine(input); return(writer); });
/// <summary> /// A reducer for adding elements to an IList. /// </summary> /// <typeparam name="TResult">The type of the values in the IList.</typeparam> /// <returns>An IReducer that pushes values to an IList.</returns> public static IReducer <IList <TResult>, TResult> ListReducer <TResult>() => Reducer.Make <IList <TResult>, TResult>((list, val) => { list.Add(val); return(list); });
public static IReducer <T, T> Checked <T>() where T : struct => Accumulating.Checked <T>().Apply(Reducer.Make <T, T>((acc, val) => val));