Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov
Last active March 31, 2016 13:15
Show Gist options
  • Save alexeyraspopov/e1d54954bb35774162b11a3cff0cf368 to your computer and use it in GitHub Desktop.
Save alexeyraspopov/e1d54954bb35774162b11a3cff0cf368 to your computer and use it in GitHub Desktop.
class KeyedCollection extends Map {
map(fn) {
const mappedEntries = Array.from(this, ([k, v]) => [k, fn(v, k, this)]);
return new this.constructor(mappedEntries);
}
mapKeys(fn) {
const mappedEntries = Array.from(this, ([k, v]) => [fn(k, v, this), v]);
return new this.constructor(mappedEntries);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment