Dmitry Soshnikov (2014-10-05T05:03:52.000Z)
On Sat, Oct 4, 2014 at 5:58 PM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:

> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of
> Domenic Denicola
>
> > Unless I'm missing something (quite possible!), I would prefer not to
> add new methods to Map and Set when they could be added to
> %IteratorPrototype%.
>
> Yeah, I'm missing something. It's the difference in code between:
>
> ```js
> var newMap = oldMap.map(([k, v]) => [k + 1, v + 1]);
> ```
>
> versus
>
> ```js
> var newMap = new Map(oldMap.entries().map((([k, v]) => [k + 1, v + 1]);
> ```
>
> I think I still prefer avoiding every iterable subclass adding its own
> map/filter/etc. in favor of people using the compositional base primitives,
> but at least I see the argument now.
>

We already have `Map#forEach`, and correlation with `Array#forEach ->
`Array#map` makes this constancy intuitive.

The only thing which Rick mentioned, is that `Map#map` should probably
return a transformed `[key, value]` pair, that allows updating the key as
well. However, need to think about it, since as mentioned on the diff [1],
usually people transform only values, and to force them always return an
array may be annoying (the key is not transformed in this case), and less
performant in terms useless array allocation.

This case I'd probably make as `Map#mapWithKey`, however there other
questions arise like, should the returned pair replace the existing, or
create a new one, if the key is different?

```
({a => 10}).mapWithKey((k, v) => ['b', 20]); // {b => 20} or {a => 20, b =>
20} ?
```

But this is for further discussion.

Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141004/c2460935/attachment.html>
forbes at lindesay.co.uk (2016-02-01T12:55:39.534Z)
We already have `Map#forEach`, and correlation with `Array#forEach` ->
`Array#map` makes this constancy intuitive.

The only thing which Rick mentioned, is that `Map#map` should probably
return a transformed `[key, value]` pair, that allows updating the key as
well. However, need to think about it, since as mentioned on the diff [1],
usually people transform only values, and to force them always return an
array may be annoying (the key is not transformed in this case), and less
performant in terms useless array allocation.

This case I'd probably make as `Map#mapWithKey`, however there other
questions arise like, should the returned pair replace the existing, or
create a new one, if the key is different?

```js
({a => 10}).mapWithKey((k, v) => ['b', 20]); // {b => 20} or {a => 20, b =>

20} ?
```

But this is for further discussion.