예제 #1
0
        static void Iterate(ConsoleInputContext context, Func <string, bool> action)
        {
            var res = IterateLowStack(context, action);

            while (res != null)
            {
                res = res.Run();
            }
        }
예제 #2
0
        static LowStack IterateLowStack(ConsoleInputContext context, Func <string, bool> action)
        {
            var next = context.Next();
            var done = action(next.Value);

            if (!done)
            {
                return(new LowStack(() => IterateLowStack(next, action)));
            }

            return(null);
        }
예제 #3
0
        static Func <ConsoleInputContext> NextConsoleInput()
        {
            ConsoleInputContext context = null;

            Func <ConsoleInputContext> next = () =>
            {
                if (context == null)
                {
                    var input = Console.ReadLine();
                    context = new ConsoleInputContext(input, NextConsoleInput());
                }
                return(context);
            };

            return(next);
        }