Skip to content

joinMappings

joinMappings<K, V>(maps, resolveConflict): Map<K, V>

Defined in: packages/core/src/map/join-mappings.ts:32

Merges several maps into one, resolving repeated keys with a stated rule.

resolveConflict is required rather than defaulted, because the default everyone reaches for — new Map([...a, ...b]) — silently keeps the last write, and a silent default is the bug this exists to prevent. Pass (_key, _existing, incoming) => incoming to ask for it deliberately.

Insertion order follows first appearance: a key repeated in a later map keeps the position it was first given, only its value changes.

Time complexity: O(total entries).

K

V

Iterable<ReadonlyMap<K, V>>

The maps to merge, in precedence order.

MappingConflictResolver<K, V>

Called once per repeated key, with the accumulated value and the incoming one.

Map<K, V>

A new map. The inputs are not modified.