Skip to content

Instantly share code, notes, and snippets.

@mieko
Created April 10, 2014 17:04
Show Gist options
  • Save mieko/10402611 to your computer and use it in GitHub Desktop.
Save mieko/10402611 to your computer and use it in GitHub Desktop.
def f
yield "trol"
yield "olol"
yield "lolo"
end
var f = function() {
continuation = {};
continuation = {
next: function() {
return continuation.body(continuation);
},
step: 0,
body: function(context) {
switch(context.step) {
case 0:
context.step = 1
return "trol";
case 1:
context.step = 2
return "olol";
case 2:
context.step = 3;
return "lolo";
default:
throw "StopIteration"
}
}
};
return continuation;
}
it = f()
console.log(it.next())
console.log(it.next())
console.log(it.next())
console.log(it.next())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment