ECMAScript feature suggestion: Streaming Array items through filter/map/reduce functions

Bergi a.d.bergi at
Fri Jun 21 21:56:06 UTC 2019


> However, when I want to write performance sensitive code, chaining these
> functions is not a good approach.
> const b = a.filter().map()
> will require 2 traversals over the whole array, up to 2*N iterations (if
> the filter passes all items).

Actually, the number of passes hardly matters. It's still linear
complexity. What makes this slow is the allocation of the unnecessary
temporary array.

> I suggest adding a capability to streamline items to these functions.

We don't need streams, JavaScript already has iterators. What we do need
are proper helper functions for those - see the existing proposal at
<>. You then can write

     const b = Array.from(a.values().filter(…).map(…))


     for (const x of a.values().filter(…).map(…))

kind regards,

More information about the es-discuss mailing list