void IDispatcher.Invoke <TAction>(TAction action) { lock (dispatchLock) { State = reducer.Invoke(State, action); } OnNext(State); }
public Terminator <TReduction> Invoke(TReduction reduction, TResult value) { var terminator = Next.Invoke(reduction, value); var terminated = CheckTermination(terminator); return(Reduction(terminator.Value, terminated: terminated)); }
void InternalDispatch(IAction action) { lock (_syncRoot) { var nextState = State = _reducer.Invoke(State, action); _observer.OnNext(nextState); } }
public Terminator <Reduction> Invoke(Reduction reduction, int value) { var result = new GuessingGameResult(); result.Guess = value; result.Result = GetResult(value); lastGuess = result; return(next.Invoke(reduction, result)); }
public override Terminator <TReduction> Invoke(TReduction reduction, TInput value) { var result = Next.Invoke(reduction, value); if (result.IsTerminated) { return(result); } return(Loop.Invoke(reduction, value)); }
public override Terminator <TReduction> Invoke(TReduction reduction, TInput value) { try { return(success.Invoke(reduction, value)); } catch (TException exception) { return(exceptional.Invoke( reduction, new ExceptionalInput <TInput, TException>(value, exception))); } }
/// <summary> /// Pulls values from the supplied TextReader and passes them into the supplied reducer. /// </summary> /// <typeparam name="TReduction">The type of the reduction.</typeparam> /// <param name="reader">The reader.</param> /// <param name="reduction">The reduction.</param> /// <param name="reducer">The reducer.</param> /// <returns>A wrapped reduction.</returns> public static Terminator <TReduction> Reduce <TReduction>( this TextReader reader, TReduction reduction, IReducer <TReduction, string> reducer) { var terminator = Terminator.Reduction(reduction); for (var value = reader.ReadLine(); value != null; value = reader.ReadLine()) { terminator = reducer.Invoke(terminator.Value, value); if (terminator.IsTerminated) { return(terminator); } } return(reducer.Complete(reduction)); }
/// <summary> /// Passes elements from an IEnumerable into the supplied reducer. /// </summary> /// <typeparam name="TInput">The type of the input.</typeparam> /// <typeparam name="TReduction">The type of the reduction.</typeparam> /// <param name="input">The input.</param> /// <param name="reduction">The reduction.</param> /// <param name="reducer">The reducer.</param> /// <returns>A terminated reduction.</returns> public static Terminator <TReduction> Reduce <TInput, TReduction>( this IEnumerable <TInput> input, TReduction reduction, IReducer <TReduction, TInput> reducer) { var terminator = Terminator.Reduction(reduction); foreach (var value in input) { terminator = reducer.Invoke(terminator.Value, value); if (terminator.IsTerminated) { return(terminator); } } return(reducer.Complete(terminator.Value)); }
public Terminator <TReduction> Invoke(TReduction reduction, TInput value) => Next.Invoke(reduction, value);
public Task <Terminator <TReduction> > InvokeAsync(TReduction reduction, TInput value) => Task.FromResult(Reducer.Invoke(reduction, value));