See https://github.com/tc39/proposal-iterator-helpers

On Sat, Jul 27, 2019 at 1:45 PM Artem Kobzar <a.kobzar....@gmail.com> wrote:

> The proposal based on really worst thing in JavaScript Arrays.
>
> If i as developer want to make declarative code with combination of
> `Array#map`, `Array#filter` or `Array#reduce` - i will take a lot of
> iterations (count of chain element will determinate count of iterations).
>
> ```js
> const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
>
> const newArr = arr
>   .map(a => a + 1)
>   .filter(a => a % 2 === 0)
>   .filter((a, i) => i < 3); // [2, 4, 6], but 3 iterations across `arr`
> ```
>
> So, my proposal is: add lazy iterator with additional functions which help
> to use declarative collection method in chain as "zero-abstraction" and
> will iterate only once (will not be related to count of chain methods).
>
> Actually, i've already created implementation and usage of this
> implementation looks like this:
>
> ```js
> const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
>
> const newArr = arr
>   .lazy()
>   .map(a => a + 1)
>   .filter(a => a % 2 === 0)
>   .take(3)
>   .collect(); // [ 2, 4, 6 ], but 1 iterations across `arr`
> ```
>
> And, actually, current implementation could be used with all `Iterable`
> objects, if this object will implement method `fromIterator` (it's needed
> for `LazyIterator#collect` method).
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to