conductor
Why I'm building conductorGitHub
v1.5.0
v1.5.0
  • Introduction
  • Overview
    • Introduction
    • Core concepts
  • API reference
    • always
    • append
    • apply
    • arity
    • branch
    • capitalize
    • compose
    • concat
    • curry
    • curryN
    • delay
    • dump
    • entries
    • equals
    • equalsBy
    • factory
    • filter
    • findIndex
    • flatten
    • flip
    • forEach
    • get
    • head
    • ifElse
    • identity
    • into
    • isPromise
    • iterate
    • join
    • keys
    • map
    • merge
    • mergeBy
    • next
    • not
    • pluck
    • prepend
    • random
    • reduce
    • replace
    • slice
    • some
    • split
    • take
    • then
    • toLowerCase
    • transduce
    • transformers
      • transformers/filter
      • transformers/map
    • type
    • upsert
    • values
  • Guides
    • example use cases
    • checkGuards
Powered by GitBook
On this page
  • description
  • examples
  1. API reference

merge

PreviousmapNextmergeBy

Last updated 6 years ago

merge :: (Any, Any) -> Any

Available since v1.3.0.

description

Deeply merges two items (primitives, or object-like values). For primitives, merge will return the right-hand side (the last argument you pass to the function). For collections (Array, Set, Map, Object), merge will recursively merge each value as follows:

  • arrays & sets: values will be deduped

  • objects & maps: values associated to the same key will be merged recursively using merge

Equality between two values is checked using .

examples

merging two primitives

import { merge } from 'conductor'

merge('hello', 'world') // 'world'
merge(2, 'world') // 'world'
merge({ hello: 'hello'}, 'world') // 'world'

When the last argument is a primitive, it will always be the returned value.

merging two collections

import { merge } from 'conductor'

merge(['hello'], ['world']) // ['hello', 'world']
merge(['hello', 'world'], ['world']) // ['hello', 'world']
merge({ hello: 'world' }, { bonjour: 'monde' }) // { hello: 'world', bonjour: 'monde' }
merge({ hello: 'world' }, { hello: 'monde' }) // { hello: 'monde' }

When they are merged, collections are deduped by value for Arrays & Sets, and by key for Objects & Maps.

merging nested collections

import { merge } from 'conductor'

merge({ words: ['hello'] }, { words: ['world'] }) // { words: ['hello', 'world'] }
merge([{ hello: 'world' }], [{ hello: 'world' }]) // [{ hello: 'world' }]

Collections are merged recursively using merge.

equals