Re: Lazy Iterators

2019-07-27 Thread Roma Bronstein
This was exactly what I proposed a few weeks ago, and received a not so
enthusiastic response.
Which is strange, as I know many developers who complain exactly about this.

In it's current state, map/reduce/filter... functions are irrelevant
performance wise in many scenarios in production environments.


On Sat, Jul 27, 2019, 23:45 Artem Kobzar  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


Re: Lazy Iterators

2019-07-27 Thread Jordan Harband
See https://github.com/tc39/proposal-iterator-helpers

On Sat, Jul 27, 2019 at 1:45 PM Artem Kobzar  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


Lazy Iterators

2019-07-27 Thread Artem Kobzar
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