resume method
Implementation
ES<A> resume() {
Stackless<A> th = this;
while (true) {
// print(" resume ... ");
if (th case Done(res: A resDone))
return Right(resDone);
else if (th case More(k: Stackless<A> Function() kMore))
return Left(kMore);
else if (th case AndThen(sub: Stackless<A> subAndThen, k: Stackless<A> Function(A) kAndThen)) {
if (subAndThen case Done(res: A resDoneInner))
th = kAndThen(resDoneInner); // rec
else if (subAndThen case More(k: Stackless<A> Function() kMoreInner))
return Left(() => kMoreInner().andThen(kAndThen));
else if (subAndThen case AndThen(sub: Stackless<A> subAndThenInner, k: Stackless<A> Function(A) kAndThenInner))
th = subAndThenInner.andThen((A s) => kAndThenInner(s).andThen(kAndThen)); // rec
}
}
}