Skip to content

Instantly share code, notes, and snippets.

@carmour24
Created September 21, 2020 17:00
Show Gist options
  • Select an option

  • Save carmour24/39be3e219d55e939bece592094cf7351 to your computer and use it in GitHub Desktop.

Select an option

Save carmour24/39be3e219d55e939bece592094cf7351 to your computer and use it in GitHub Desktop.
Quick method for mapping the entries in a map resulting in a new map.
const mapMap = (inputMap, mapping) => {
const _map = (iterator, mapping) => {
const entry = iterator.next()
return entry.done
? []
: [[entry.value[0], mapping(entry.value)], ..._map(iterator, mapping)]
}
const iterator = inputMap[Symbol.iterator]()
const mappingResultEntries = _map(iterator, mapping)
return new Map(mappingResultEntries)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment