2 ms·
You could require the caller to keep an opaque handle, and have all the state encapsulated on that handle. The caller won't know if this state is messy or not,
by gugagore 6y ago
You could require the caller to keep an opaque handle, and have all the state encapsulated on that handle. The caller won't know if this state is messy or not, and I think this does a good job of encapsulating annoying complexity.
But it doesn't prevent the caller from passing the handle to another function, or copying the handle, which could mess things up, and I suppose `yield` helps with that.
But most of all, I'd say it makes it easier to write the callee code, not the caller code, since the callee does not need to "reify" the state of "current chunk" and "chunks remaining" into an object, nor (more crucially) the state of loops and other control flow.
- iudqnolq 6y agoAbsolutely. It's like how async can be replaced with a struct and a giant switch statement, but that's a PITA to write manually.