4 ms·
I don't think this is strictly true: if your parser module also implemented the iterator/iterable protocols[0], then you could compose them that way. That may o
by tragic 11y ago
I don't think this is strictly true: if your parser module also implemented the iterator/iterable protocols[0], then you could compose them that way. That may or may not be good enough for a particular use case.
In order to get my head around all this stuff, I made a trivial little toy library using generators for basic lazy sequences, and providing some basic stuff from the lodash/underscore library for them.
I found it was enough to make a kind of wrapper class that would hold a reference to the generator function, but lazily initialise it only when client code consumed the iterator, or explicitly forced evaluation. At that point, clients are aware only of the iterable interface, and not at all of the implementation details. (Or, they wouldn't be, if the particular implementation details didn't require you to use a polyfill on 90% of browsers and VMs ;-) )
[0] https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...
- deleted 11y ago[deleted]