5 ms·
I do wish that JS had more builtin syntactic sugar around generators (and particularly async generators). They would be a lot more convenient and syntactically
by wefarrell 4y ago
I do wish that JS had more builtin syntactic sugar around generators (and particularly async generators). They would be a lot more convenient and syntactically cleaner if most of the Array builtins could also be used for iterators. For async iterators the builtins would need to leverage the promise builtins as well, so you could to something like:
const result = await asyncIterator.map(doSomethingAsync).reduce(asyncAggregatorFn)
Without ever having to load all of your data into memory.
- mirekrusin 4y agoYou may be interested in: - https://github.com/preludejs/async-generator https://github.com/preludejs/async-generator - https://github.com/preludejs/generator https://github.com/preludejs/generator ...and example usage https://observablehq.com/@mirek/project-euler https://observablehq.com/@mirek/project-euler
- c-baby 4y agoYou can do something like that with rxjs.
- michaelsbradley 4y agoYou might be interested in what IxJS has to offer: https://github.com/ReactiveX/IxJS https://github.com/ReactiveX/IxJS RxJS is for observables. IxJS is for iterables. Or, a bit more accurately, as explained in the readme: IxJS unifies both synchronous and asynchronous pull-based collections, just as RxJS unified the world of push-based collections. RxJS is great for event-based workflows where the data can be pushed at the rate of the producer, however, IxJS is great at I/O operations where you as the consumer can pull the data when you are ready.
- bakkoting 4y agoThere's an active proposal which would let you do exactly that, going for stage 3 (ready for implementations) at the end of the month: https://github.com/tc39/proposal-iterator-helpers https://github.com/tc39/proposal-iterator-helpers