2 ms·
The author mentions iterator helpers [1], which could make stuff easier. However, there is also a different proposal that touches different similar issue which
by nikeee 4y ago
The author mentions iterator helpers [1], which could make stuff easier.
However, there is also a different proposal that touches different similar issue which might fix this too: The bind operator proposal [2].
Like the name implies, it allows to set the `this` for a function call. This opens the possibility to implement the common map/filter/reduce functions in a lazy manner _for arrays_. Taken from the samples, this could evaluate lazily on an array returned by `getPlayers()`.
import { map, takeWhile, forEach } from "iterlib";
getPlayers()
::map(x => x.character())
::takeWhile(x => x.strength > 100)
::forEach(x => console.log(x));
Of course, this could also be used for iterators. However, the binding operator is not very active any more.
[1]: https://www.proposals.es/proposals/Iterator%20helpers https://www.proposals.es/proposals/Iterator%20helpers
[2]: https://github.com/tc39/proposal-bind-operator https://github.com/tc39/proposal-bind-operator
- inbx0 4y agoThe pipeline operator [1] is a bit further along, although I'm not exactly holding my breath for it either. At least it currently has a champion. With pipelines import { map, takeWhile, forEach } from "iterlib"; getPlayers() |> map(%, x => x.character()) |> takeWhile(%, x => x.strength > 100) |> forEach(%, x => console.log(x)); 1: https://github.com/tc39/proposal-pipeline-operator https://github.com/tc39/proposal-pipeline-operator