On Tue, Oct 7, 2014 at 11:46 AM, Domenic Denicola <
[email protected]> wrote:

> From: es-discuss [mailto:[email protected]] On Behalf Of
> Dmitry Soshnikov
>
> > Am I still missing something?
>
> Yes.
>
> ```js
> var uint16s = new Uint16Array([258]);
> var uint8s = Uint8Array.from(uint16s, x => x / 2);
> console.log(uint8s); // [129]
> ```
>
> ```js
> var uint16s = new Uint16Array([258]);
> var uint8s = Uint8Array.from(uint16s).map(x => x / 2);
> console.log(uint8s); // [1]
> ```
>
>
Moreover, these two examples are semantically completely different. They
confuse and substitute the pre- and post- mapping. Clearly, it should be
pre-mapping here, and the second example is not even correct from this
perspective. And exactly manually pre-map it, is seems better, because that
`mapfn` on the API level can simply be confusing: what does it do -- maps
pre- or post?

And as mentioned above, after the correct list is constructed (with
possible pre-mapping), developers can also post-map it calling the
`Array.prototype.map` that still preserves the kind of the collection.

So I'd say, we should exclude the `mapfn` from `Array.from` in order to
keep the implementation (including polyfills) simpler and responsible for
only one things -- building a <ArrayKind> collection from another
collection or an iterable, consuming _correct_ data.

Dmitry
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to