示例#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));