static void Iterate(ConsoleInputContext context, Func <string, bool> action) { var res = IterateLowStack(context, action); while (res != null) { res = res.Run(); } }
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); }
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); }