Version: v0.7.1 - Beta.  We welcome contributors & feedback.

Map.merge

merge($otherMap, $options = {}) -> map

Description

Merge with the key/value pairs of another map.

By default, if there are overlapping keys, the values of $otherMap will overwrite them.

$map = { a: 1, z: 9 }

$map.merge({ b: 22, z: 99 })
//= { a: 1, b: 22, z: 99 }

An example of using merge to override defaults.

$defaultCar = {
    color: 'blue',
    speed: 'medium',
    seats: 2,
}

$preferredCar = {
    color: 'red'
    speed: 'fast'
}

$finalCar = $defaultCar.merge($preferredCar)
// {
//     color: 'red',
//     speed: 'fast',
//     seats: 2,
// }

Options

Option Value Description
deep true/false Recursively merge nested maps.
$map = {
    inner: {
        x: 1,
        y: 2,
    },
    outer: 9,
}
$map.merge({ inner: { y: 222, z: 333 } }, -deep)

// {
//    inner: {
//        x: 1,
//        y: 222,
//        z: 333,
//    },
//    outer: 9,
// }