static void Iterate(EmptyConsoleInputContext context, Func <string, bool> action) { var next = context.Next(); var done = action(next.Value); if (!done) { Iterate(next, action); } }
static void Main(string[] args) { var t1 = new Test1 { Value = 23 }; var v = new Union <Test1, Test2>(t1); var result = v.Match( t1 => t1.Value, t2 => t2.Value ); v.Match( t1 => Console.WriteLine("Test1"), t2 => Console.WriteLine("Test2") ); Console.WriteLine(result); var input1 = new EmptyConsoleInputContext(NextConsoleInput()); var input2 = input1.Next(); Console.WriteLine(input2.Value); var input3 = input1.Next(); Console.WriteLine(input3.Value); var input4 = input2.Next(); Console.WriteLine(input4.Value); var input5 = input3.Next(); Console.WriteLine(input5.Value); Iterate(input1, t => { Console.WriteLine(t); StackTrace st = new StackTrace(true); Console.WriteLine($"stack size: {st.FrameCount}"); return(t == "quit"); }); }