public Cont(ITrampoline <T> next, Func <T, ITrampoline <T2> > transform) { Func <object, object> replacement = o => transform((T)o); _next = next; _transform = replacement; }
public static T Run <T>(this ITrampoline <T> self) { object o = null; var stack = new Stack <Func <object, object> >(); var next = (ITrampoline)self; var isDone = false; while (!isDone) { var data = next.RunStep(); if (data[0] != null) { next = (ITrampoline)data[0]; } if (data[1] != null) { stack.Push((Func <object, object>)data[1]); } if (data[2] != null) { o = data[2]; if (stack.Count == 0) { isDone = true; } else { var apply = true; while (apply) { var f = stack.Pop(); var temp = f(o); if (temp is ITrampoline) { apply = false; next = (ITrampoline)temp; } else { o = temp; } if (apply && stack.Count == 0) { apply = false; isDone = true; } } } } } return((T)o); }
public Io(ITrampoline <T> step) { Step = step; }
public static ITrampoline <T2> Select <T, T2>(this ITrampoline <T> m, Func <T, T2> f) { return(new Transform <T, T2>(m, f)); }
public static ITrampoline <T2> SelectMany <T, T2>(this ITrampoline <T> m, Func <T, ITrampoline <T2> > f) { return(new Cont <T, T2>(m, f)); }