public async Task <Terminator <TReduction> > CompleteAsync(TReduction reduction) { var filteringUnterminated = Core.Filtering <AsyncReducerOption>(option => !option.IsTerminated); var invokesCompletion = Reducer.AsyncMake <Terminator <TReduction>, AsyncReducerOption>((terminator, option) => option.Reducer.CompleteAsync(terminator.Value)); var reduceTask = Reducers.ReduceAsync( Reduction(reduction), filteringUnterminated.Apply(invokesCompletion)); return((await reduceTask.ConfigureAwait(false)).Value); }
private async Task <Terminator <TReduction> > EachReducer( TReduction reduction, Func <TReduction, IAsyncReducer <TReduction, TInput>, Task <Terminator <TReduction> > > func) { return((await Reducers.ReduceAsync(Reduction(reduction), Reducer.AsyncMake <Terminator <TReduction>, IAsyncReducer <TReduction, TInput> >( async(terminator, reducer) => { terminator = await func(terminator.Value, reducer); return Reduction(terminator, terminated: terminator.IsTerminated); }))).Value); }
/// <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); });