toMapByKey
Builds a Map from a Set, keyed by a derived key. When two values derive the same key,
the later value (in iteration order) wins (last-write-wins, matching Map.prototype.set).
Named toMapByKey, not keyBy (lodash’s name for the same idea) — lodash’s _.keyBy
returns a plain object, not a Map; the to<Type> prefix (matching toSorted/toReversed)
makes the actual return type unambiguous.
Available since v3.0.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
set | ReadonlySet<T> | The Set to index |
fn | function | Function deriving the key for each value |
Returns
Section titled “Returns”Map<K, T> — A Map from derived key to value
Examples
Section titled “Examples”Turn a Set into a lookup Map
Section titled “Turn a Set into a lookup Map”Builds a Map keyed by a derived value, for O(1) lookup by that key.
