>>101187038
I derived this intuitively but I don't understand why it works.
function foo(next) {
console.log("foo");
return next;
}
function bar(next) {
console.log("bar");
return next;
}
function delay(f) {
return ((x) => (() => f(x)));
}
let lst = [
foo,
foo,
bar,
foo,
foo,
bar,
foo,
foo,
foo
].reverse();
let seq = null;
for(let f of lst) {
seq = delay(f)(seq);
}
while(seq) {
seq = seq();
}