November 25th, 2017

(no subject)

I've been burned by the fact that JavaScript’s native Object.assign method or Lodash's merge function mutate the first object that is passed to them more often than I would like to admit. As in:

a = { foo: 'bar' }
b = { x: 'y' }
c = Object.assign(a, b)

// c: {foo: "bar", x: "y"}
// a: {foo: "bar", x: "y"}


Ramda's merge, in contrast, being much better-behaved, does not mutate the passed objects:

a = { foo: 'bar' }
b = { x: 'y' }
c = Ramda.merge(a, b)

// c: { foo: "bar", x: "y" }
// a: { foo: "bar" }