Rick Waldron (2014-10-01T20:48:32.000Z)
On Wed, Oct 1, 2014 at 4:38 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

> Ah, thanks! Then I’d wrap the result of `entries()` in `Array.from()`. In
> ES7, we’ll hopefully be able to use comprehensions or iterator helper
> functions.
>

Don't need to do that either.

let map1 = new Map([[-1, -1], [0, 0], [1, 1], [2, 2]]);
let map2 = new Map([...map1].filter(([key, value]) => key >= 0));
let map3 = new Map([...map1].map(([key, value]) => [key * 2, value * 2]));

console.log([...map2]); // [[0, 0], [1, 1], [2, 2]]
console.log([...map3]); // [[-2, -2], [0, 0], [2, 2], [4, 4]]


Rick



>
>
> On Oct 1, 2014, at 22:27 , Rick Waldron <waldron.rick at gmail.com> wrote:
>
>
>
> On Wed, Oct 1, 2014 at 4:17 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
>
>> On Oct 1, 2014, at 22:12 , Axel Rauschmayer <axel at rauschma.de> wrote:
>>
>> 1. Transforming iteration methods
>>
>> We're currently polyfillying the `Map`, and got some questions form devs.
>> One of them is about transforming iteration methods, like `map` and
>> `filter`.
>>
>> Unfortunately I missed that part of the spec when it was approved, so can
>> someone please remind/clarify -- was it an intended decision not to hap
>> Map#map, Map#filter? I can see only Map#forEach in the spec. Are maps
>> "immutable"? -- That's fine, the `map` and `filter` return a new map.
>>
>>
>> FWIW: I’ll probably use the following work-arounds. I don’t expect
>> performance to be an issue for my applications; it’d be interesting to hear
>> if it becomes a problem for someone.
>>
>> ```js
>> let map2 = new Map(map1.entries().filter((key, value) => key >= 0));
>> let map2 = new Map(map1.entries().map((key, value) => [key * 2, value *
>> 2]));
>>
>> entries() returns an iterator, not an array.
>
> Rick
>
>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
> rauschma.de
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141001/542b1fbc/attachment.html>
forbes at lindesay.co.uk (2016-02-01T12:48:32.674Z)
> Ah, thanks! Then I’d wrap the result of `entries()` in `Array.from()`.

Don't need to do that either.

```js
let map1 = new Map([[-1, -1], [0, 0], [1, 1], [2, 2]]);
let map2 = new Map([...map1].filter(([key, value]) => key >= 0));

let map3 = new Map([...map1].map(([key, value]) => [key * 2, value * 2]));

console.log([...map2]); // [[0, 0], [1, 1], [2, 2]]
console.log([...map3]); // [[-2, -2], [0, 0], [2, 2], [4, 4]]
```