Example #1
0
        /// <summary>
        /// C# port of Scala's orElse method for partial function chaining.
        /// See http://scalachina.com/api/scala/PartialFunction.html
        /// </summary>
        /// <param name="original">The original <see cref="StateFunction" /> to be called</param>
        /// <param name="fallback">The <see cref="StateFunction" /> to be called if <paramref name="original" /> returns null</param>
        /// <returns>
        /// A <see cref="StateFunction" /> which combines both the results of <paramref name="original" /> and
        /// <paramref name="fallback" />
        /// </returns>
        private static StateFunction OrElse(StateFunction original, StateFunction fallback)
        {
            StateFunction chained = (@event, state) =>
            {
                var originalResult = original.Invoke(@event, state);
                if (originalResult == null)
                {
                    return(fallback.Invoke(@event, state));
                }
                return(originalResult);
            };

            return(chained);
        }
Example #2
0
        /// <summary>
        /// C# port of Scala's orElse method for partial function chaining.
        ///
        /// See http://scalachina.com/api/scala/PartialFunction.html
        /// </summary>
        /// <param name="original">The original <see cref="StateFunction"/> to be called</param>
        /// <param name="fallback">The <see cref="StateFunction"/> to be called if <paramref name="original"/> returns null</param>
        /// <returns>A <see cref="StateFunction"/> which combines both the results of <paramref name="original"/> and <paramref name="fallback"/></returns>
        private static StateFunction OrElse(StateFunction original, StateFunction fallback)
        {
            StateFunction chained = delegate(Event <TData> @event)
            {
                var originalResult = original.Invoke(@event);
                if (originalResult == null)
                {
                    return(fallback.Invoke(@event));
                }
                return(originalResult);
            };

            return(chained);
        }
Example #3
0
        /// <summary>
        ///     C# port of Scala's orElse method for partial function chaining.
        ///     See http://scalachina.com/api/scala/PartialFunction.html
        /// </summary>
        /// <param name="original">The original <see cref="StateFunction" /> to be called</param>
        /// <param name="fallback">The <see cref="StateFunction" /> to be called if <paramref name="original" /> returns null</param>
        /// <returns>
        ///     A <see cref="StateFunction" /> which combines both the results of <paramref name="original" /> and
        ///     <paramref name="fallback" />
        /// </returns>
        private static StateFunction OrElse(StateFunction original, StateFunction fallback)
        {
            StateFunction chained = delegate(FSMBase.Event <TData> @event, State <TState, TData, TEvent> state)
            {
                var originalResult = original.Invoke(@event, state);
                if (originalResult == null)
                {
                    return(fallback.Invoke(@event, state));
                }
                return(originalResult);
            };

            return(chained);
        }