Skip to content

unctionjs/mergeWithKey

Repository files navigation

@unction/mergeWithKey

Tests Stability Dependencies

MapperFunctionType<L, MapperFunctionType<R, MapperFunctionType<K, V>>> => KeyedEnumerableType<R, K> => KeyedEnumerableType<L, K> => ListType | Record<string | number | symbol, V> | Map<K, V> | string

Merges two keyed enumerables and uses a function to handle conflicts. The function is given the left value, the right value, and the key.

const left = {
  beta: "1"
}
const right = {
  beta: "2"
}

mergeWithKey((left) => (right) => (key) => key+leftValue+rightValue)(left)(right)

Which returns:

{
  beta: "beta12"
}