示例#1
0
        public static void Bounce(this Trampoline trampoline)
        {
            RecursiveAction recursiveAction = null;

            for (
                recursiveAction = () => recursiveAction;

                recursiveAction != null;

                recursiveAction = trampoline(recursiveAction)()
                )
            {
            }
        }
示例#2
0
        public static void Bounce <T>(this Trampoline <T> trampoline, T arg)
        {
            RecursiveAction <T> recursiveAction = null;

            for (
                recursiveAction = (newArg) =>
            {
                arg = newArg;
                return(recursiveAction);
            };

                recursiveAction != null;

                recursiveAction = trampoline(recursiveAction)(arg)
                )
            {
            }
        }
        public static TResult Bounce <T1, TResult>(this Trampoline <T1, TResult> trampoline, T1 inputValue)
        {
            object result;
            RecursionModifier <T1, TResult> recursiveFunc = null;

            recursiveFunc = input =>
            {
                inputValue = input;
                return(recursiveFunc);
            };

            while (!ResultsByDelegate.TryGetValue(recursiveFunc, out result))
            {
                recursiveFunc = trampoline(recursiveFunc)(inputValue);
            }
            ResultsByDelegate.Remove(recursiveFunc);
            return((TResult)result);
        }
        public static TResult Bounce <TResult>(this Trampoline <TResult> trampoline)
        {
            object result;
            RecursionModifier <TResult> recursiveFunc = null;

            for (
                recursiveFunc = () => recursiveFunc;                       // no arguments

                !ResultsByDelegate.TryGetValue(recursiveFunc, out result); // exit if results exist for the function

                recursiveFunc = trampoline(recursiveFunc)()                // call recursion
                )
            {
            }

            ResultsByDelegate.Remove(recursiveFunc);
            return((TResult)result);
        }
示例#5
0
        public static void Bounce <T1, T2>(this Trampoline <T1, T2> trampoline, T1 arg1, T2 arg2)
        {
            RecursiveAction <T1, T2> recursiveAction = null;

            for (
                recursiveAction = (newArg1, newArg2) =>
            {
                arg1 = newArg1;
                arg2 = newArg2;
                return(recursiveAction);
            };

                recursiveAction != null;

                recursiveAction = trampoline(recursiveAction)(arg1, arg2)
                )
            {
            }
        }
        public TReturn StartWith(T1 initialInput)
        {
            ChangeInput(initialInput);

            while (!_stopping)
            {
                _instance = _instance._work(_instance.Input, _instance);
            }
            return(Result);
        }
        public static TResult Bounce <T1, T2, TResult>(this Trampoline <T1, T2, TResult> trampoline, T1 inputValue1, T2 inputValue2)
        {
            object result;
            RecursionModifier <T1, T2, TResult> recursiveFunc = null;

            for (
                recursiveFunc = (input1, input2) =>
            {
                inputValue1 = input1;                         // let the argument change
                inputValue2 = input2;
                return(recursiveFunc);
            };

                !ResultsByDelegate.TryGetValue(recursiveFunc, out result);          // exit if results exist for the function

                recursiveFunc = trampoline(recursiveFunc)(inputValue1, inputValue2) // call recursion
                )
            {
            }

            ResultsByDelegate.Remove(recursiveFunc);
            return((TResult)result);
        }
        public static Trampoline <T1, TReturn> Bounce(Func <T1, Trampoline <T1, TReturn>, Trampoline <T1, TReturn> > work)
        {
            var instance = new Trampoline <T1, TReturn>(work);

            return(instance);
        }