예제 #1
0
 void IDispatcher.Invoke <TAction>(TAction action)
 {
     lock (dispatchLock)
     {
         State = reducer.Invoke(State, action);
     }
     OnNext(State);
 }
예제 #2
0
                public Terminator <TReduction> Invoke(TReduction reduction, TResult value)
                {
                    var terminator = Next.Invoke(reduction, value);

                    var terminated = CheckTermination(terminator);

                    return(Reduction(terminator.Value, terminated: terminated));
                }
예제 #3
0
 void InternalDispatch(IAction action)
 {
     lock (_syncRoot)
     {
         var nextState = State = _reducer.Invoke(State, action);
         _observer.OnNext(nextState);
     }
 }
예제 #4
0
            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));
            }
예제 #5
0
            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));
            }
예제 #6
0
 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)));
     }
 }
예제 #7
0
        /// <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));
        }
예제 #8
0
        /// <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));
        }
예제 #9
0
 public Terminator <TReduction> Invoke(TReduction reduction, TInput value) =>
 Next.Invoke(reduction, value);
예제 #10
0
 public Task <Terminator <TReduction> > InvokeAsync(TReduction reduction, TInput value) =>
 Task.FromResult(Reducer.Invoke(reduction, value));