Example #1
0
 /// <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);
 });
Example #2
0
 /// <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);
 });
Example #3
0
 /// <summary>
 /// Returns a reducer that writes the input to a TextWriter.
 /// </summary>
 /// <returns>A reducer.</returns>
 public static IAsyncReducer <TextWriter, string> AsyncWriteReducer() =>
 Reducer.AsyncMake <TextWriter, string>(async(writer, input) =>
 {
     await writer.WriteAsync(input).ConfigureAwait(false);
     return(writer);
 });
Example #4
0
 public static IReducer <T, T> Checked <T>() where T : struct =>
 Accumulating.Checked <T>().Apply(Reducer.Make <T, T>((acc, val) => val));