3 ms·
Sorry for being thick. You said: The power of the generator is that, unlike an iterator, the collection of values doesn't "exist", it is created on the fly. W
by redditor98654 3y ago
Sorry for being thick. You said:
The power of the generator is that, unlike an iterator, the collection of values doesn't "exist", it is created on the fly.
What is a specific example where this is true?
- cratermoon 3y agoPython: <https://wiki.python.org/moin/Generators https://wiki.python.org/moin/Generators> Javascript: <https://www.digitalocean.com/community/tutorials/understanding-generators-in-javascript#infinite-data-streams https://www.digitalocean.com/community/tutorials/understandi...> The Python example is more to the point. The Javascript one gets there, but goes in a roundabout way.
- redditor98654 3y agoI still don't see where the iterator version would need to have all the values already exist but thanks for the links. To me it seems the benefit is conciseness of the implementation and its usage at the call site.