Hacker News new | ask | show | jobs
by _xgw 2702 days ago
> Consecutive calls to next() will always produce { done: true }.

Not necessarily. You can make recursive generators which never "terminate". For example, here's a codegolfed version of a recursive generator which represents a n + 1 sequence:

    p=function*a(x){yield x;yield*a(x+1)}(0)
1 comments

I meant there "[Once the generator has completed], Consecutive calls to `next()` will always produce `{ done: true }`".

I should probably make it more explicit

PS: I like your n+1 example.