2 ms·
Well, you can't iterate a generator without invoking it. If you returned a generator you can't `for(let x of myGeneratorFn)` because it's not an iterable - rath
by inglor 12y ago
Well, you can't iterate a generator without invoking it. If you returned a generator you can't `for(let x of myGeneratorFn)` because it's not an iterable - rather a generator is just sugar for a function that returns an iterable. You'd have to do `for(let x of myGeneratorFn())` although in this case I agree it's silly to return it like this.
- scotty79 12y agoHe couldn't return generator instance because he needs two instances of game running at the same time for the tortoise and hare algorithm to run in const memory. He would need to return at least generator function but that would force him to invoke it before iterating.