You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current Iterables class has been created to offer basic utility functions for iteration. These should have been part of the core language specification since the Iterator concept was established, but ... haven't. Given some possible upcoming refactorings (e.g. in the context of #156 ), the same functionalities will also be required for asynchronous iterators.
There are several options for the "other solutions" mentioned in the title:
There certainly are dozens of existing libraries that offer similar functionality, and much (MUCH) more that could be useful here. (and ... are better tested). Some of them are listed in https://github.com/tc39/proposal-iterator-helpers?tab=readme-ov-file#prior-art--userland-implementations . But a built-in solution would be preferable in many ways (particularly because it's not clear when and how these libraries will catch up with asnychronous iteration protocols...)
Note: When looking at the functions in Iterables, one might wonder why they are written in this seemingly complicated way of always creating a resultIterable ... [Symbol.iterator] ... Some of the "boilerplate" code there could be avoided (with some private static createIterator(...) function or so). But the underlying issue here is that a JavaScript Generator concept is ... well, I'll just call it "broken": It is an iterator that looks like an iterable. But it is iterable only once:
function*create(){yield"ELEMENT0001";yield"ELEMENT0002";yield"ELEMENT0003";yield"ELEMENT0004";}functionexample(){constiterable=create();console.log("Let's iterate, because it's iterable");for(constelementofiterable){console.log(element);}console.log("Let's try that again, because it's iterable");for(constelementofiterable){console.log(element);}console.log("Whoopsie, why didn't it show anything?");}example();
In order to have something that is truly iterable, one has to create the Generator==Iterator each time when an iterator is requested.
The text was updated successfully, but these errors were encountered:
The current
Iterables
class has been created to offer basic utility functions for iteration. These should have been part of the core language specification since theIterator
concept was established, but ... haven't. Given some possible upcoming refactorings (e.g. in the context of #156 ), the same functionalities will also be required for asynchronous iterators.There are several options for the "other solutions" mentioned in the title:
The last one would be the most desirable. And it looks like in the meantime (roughly a month ago), https://github.com/tc39/proposal-iterator-helpers has been brought on its way to become part of the core standard (but who knows how long that will take). That won't be enough, though: We'd still have to wait for https://github.com/tc39/proposal-async-iterator-helpers ...
There certainly are dozens of existing libraries that offer similar functionality, and much (MUCH) more that could be useful here. (and ... are better tested). Some of them are listed in https://github.com/tc39/proposal-iterator-helpers?tab=readme-ov-file#prior-art--userland-implementations . But a built-in solution would be preferable in many ways (particularly because it's not clear when and how these libraries will catch up with asnychronous iteration protocols...)
Note: When looking at the functions in
Iterables
, one might wonder why they are written in this seemingly complicated way of always creating aresultIterable ... [Symbol.iterator] ..
. Some of the "boilerplate" code there could be avoided (with someprivate static createIterator(...)
function or so). But the underlying issue here is that a JavaScriptGenerator
concept is ... well, I'll just call it "broken": It is an iterator that looks like an iterable. But it is iterable only once:In order to have something that is truly iterable, one has to create the Generator==Iterator each time when an iterator is requested.
The text was updated successfully, but these errors were encountered: