Cyril Auburtin (2018-03-15T14:52:19.000Z)
I totally agree that Map (and Set) should have `.map`, `.filter` and a few
more (`.slice`, ..) methods, similarly to immutableJS. Since Maps and Sets
are ordered, it would make sense

example polyfill:

```js
class SortableMap {
constructor(data) {
this.m = new Map(Array.isArray(data) ? data : Object.entries(data));
}
set(k, v) {
this.m.set(k, v);
return this;
}
get(k) {
return this.m.get(k);
}
forEach(fn) {
this.m.forEach(fn);
}
map(fn) {
return Array.from(this.m, fn);
}
sort(fn) {
const a = [...this.m].sort((x, y) => fn(x[1], y[1])); // sort with values
this.m = new SortableMap(a);
return this;
}
*[Symbol.iterator]() {
yield* this.m;
}
}
const m = new SortableMap([['lol', 'far'], ['ok', 'boo']]);
m.sort((a, b) => a.localeCompare(b));
console.log(1, m);
// 1 SortableMap { m: SortableMap { m: Map { 'ok' => 'boo', 'lol' => 'far'
} } }
m.set('bip', 'cri');
console.log(2, m.map());
// 2 [ [ 'ok', 'boo' ], [ 'lol', 'far' ], [ 'bip', 'cri' ] ]
m.sort((a, b) => a.localeCompare(b));
console.log(3, m.map());
// 3 [ [ 'ok', 'boo' ], [ 'bip', 'cri' ], [ 'lol', 'far' ] ]
```

2018-01-20 1:38 GMT+01:00 Michał Wadas <michalwadas at gmail.com>:

> Hi.
>
> With Set methods being discussed on next TC39 I would like to write second
> proposal - Map methods.
>
> Currently I thought about:
>
> Map.prototype.filter(cb, thisArg)
> Map.prototype.mapValues(cb, thisArg)
> Map.prototype.mapKeys(cb, thisArg)
> Map.prototype.merge(iterable: Iterable.<Tuple.<*, *>>)
>
> Map.groupBy(iterable, keyDerivativeFunc) - analogus to lodash.groupBy
> <https://lodash.com/docs/4.17.4#groupBy>, but returning Map Instance.
> Map.keyBy(iterable, keyDerivativeFunc) - analogous to lodash.keyBy, but
> returning Map instance.
>
> I spend few minutes on writing code for simple polyfill -
> https://github.com/Ginden/map-methods/blob/master/polyfill.js and I'm
> gathering opinions what would be expected final shape of Map API.
>
> Michał Wadas
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180315/d368e02a/attachment.html>
cyril.auburtin at gmail.com (2018-03-15T14:58:18.487Z)
I totally agree that Map (and Set) should have `.map`, `.filter` and a few
more (`.slice`, ..) methods, similarly to immutableJS. Since Maps and Sets
are ordered, it would make sense

example polyfill:

```js
class SortableMap {
  constructor(data) {
    this.m = new Map(Array.isArray(data) ? data : Object.entries(data));
  }
  set(k, v) {
    this.m.set(k, v);
    return this;
  }
  get(k) {
    return this.m.get(k);
  }
  forEach(fn) {
    this.m.forEach(fn);
  }
  map(fn) {
    return Array.from(this.m, fn);
  }
  sort(fn) {
    const a = [...this.m].sort((x, y) => fn(x[1], y[1])); // sort with values

    this.m = new SortableMap(a);
    return this;
  }
  *[Symbol.iterator]() {
    yield* this.m;
  }
}
const m = new SortableMap([["lol", "far"], ["ok", "boo"]]);
m.sort((a, b) => a.localeCompare(b));
console.log(1, m);
// 1 SortableMap { m: SortableMap { m: Map { 'ok' => 'boo', 'lol' => 'far'
m.set("bip", "cri");
console.log(2, m.map());
// 2 [ [ 'ok', 'boo' ], [ 'lol', 'far' ], [ 'bip', 'cri' ] ]
m.sort((a, b) => a.localeCompare(b));
console.log(3, m.map(([k, v]) => [k, v + "!"]));
// 3 [ [ 'ok', 'boo!' ], [ 'bip', 'cri!' ], [ 'lol', 'far!' ] ]
```

2018-01-20 1:38 GMT+01:00 Michał Wadas <michalwadas at gmail.com>:
cyril.auburtin at gmail.com (2018-03-15T14:54:44.174Z)
I totally agree that Map (and Set) should have `.map`, `.filter` and a few
more (`.slice`, ..) methods, similarly to immutableJS. Since Maps and Sets
are ordered, it would make sense

example polyfill:

```js
class SortableMap {
  constructor(data) {
    this.m = new Map(Array.isArray(data) ? data : Object.entries(data));
  }
  set(k, v) {
    this.m.set(k, v);
    return this;
  }
  get(k) {
    return this.m.get(k);
  }
  forEach(fn) {
    this.m.forEach(fn);
  }
  map(fn) {
    return Array.from(this.m, fn);
  }
  sort(fn) {
    const a = [...this.m].sort((x, y) => fn(x[1], y[1])); // sort with values

    this.m = new SortableMap(a);
    return this;
  }
  *[Symbol.iterator]() {
    yield* this.m;
  }
}
const m = new SortableMap([['lol', 'far'], ['ok', 'boo']]);
m.sort((a, b) => a.localeCompare(b));

console.log(1, m);
// 1 SortableMap { m: SortableMap { m: Map { 'ok' => 'boo', 'lol' => 'far'
} } }
m.set('bip', 'cri');
console.log(2, m.map());
// 2 [ [ 'ok', 'boo' ], [ 'lol', 'far' ], [ 'bip', 'cri' ] ]
m.sort((a, b) => a.localeCompare(b));

console.log(3, m.map());
// 3 [ [ 'ok', 'boo' ], [ 'bip', 'cri' ], [ 'lol', 'far' ] ]
```

2018-01-20 1:38 GMT+01:00 Michał Wadas <michalwadas at gmail.com>: