Skip to content

Map Helpers

Utility functions for working with map operations.

Function Description
countBy Groups the entries of a Map by a derived key and counts how many fall into each group.
every Checks if every entry of a Map satisfies the predicate.
filter Creates a new Map containing only the entries for which the predicate returns true.
findKey Returns the first key of a Map whose entry satisfies the predicate, in insertion order.
findKey / findValue native JS map.entries().find(([k, v]) => pred(v, k))?.[0 or 1] (ES2025 (Iterator Helpers))
findValue Returns the first value of a Map whose entry satisfies the predicate, in insertion order.
forEach native JS Map.prototype.forEach((value, key, map) => ...) (ES2015)
groupBy native JS Map.groupBy(map.entries(), ([k, v]) => groupFn(v, k)) (ES2024)
hasValue Checks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).
hasValue native JS map.values().some(v => Object.is(v, value)) (ES2025 (Iterator Helpers))
mapKeys Creates a new Map with the same values but with each key transformed by a function.
mapValues Creates a new Map with the same keys but with each value transformed by a function.
reduce Reduces a Map to a single value by applying a function to each entry, in insertion order.
reduce / some / every native JS map.entries().reduce(fn, init) / .some(fn) / .every(fn) (ES2025 (Iterator Helpers))
some Checks if at least one entry of a Map satisfies the predicate.
toMapByKey Builds a Map from an iterable of items, keyed by a derived key.