Repository: rtfeldman/seamless-immutable
Pull request #156 (2016-10-12 03:47:04)

Update deep merge() to work with an array argument
Had to pull these changes to a branch in my fork to avoid editing history of master. This should be the same as #140, which I will close out.


Patch:
diff --git a/seamless-immutable.development.js b/seamless-immutable.development.js
index e2e2e81..6d2e8f6 100644
--- a/seamless-immutable.development.js
+++ b/seamless-immutable.development.js
@@ -398,7 +398,7 @@
 
         for (key in otherFromArray) {
           if (otherFromArray.hasOwnProperty(key)) {
-            addToResult(this, otherFromArray, key);
+            addToResult(result !== undefined ? result : this, otherFromArray, key);
           }
         }
       }
diff --git a/seamless-immutable.development.min.js b/seamless-immutable.development.min.js
index 6b71172..6982538 100644
--- a/seamless-immutable.development.min.js
+++ b/seamless-immutable.development.min.js
@@ -1,1 +1,1 @@
-/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b,c){a(b,c,function(){throw new f("The "+c+" method cannot be invoked on an Immutable data structure.")})}function c(b){a(b,G,!0)}function d(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,G)):!0}function e(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function f(a){var b=new Error(a);return b.__proto__=f,b}function g(a,d){c(a);for(var e in d)d.hasOwnProperty(e)&&b(a,d[e]);return Object.freeze(a),a}function h(b,c){var d=b[c];a(b,c,function(){return D(d.apply(b,arguments))})}function i(a,b){if(a in this&&this[a]===b)return this;var c=p.call(this);return c[a]=D(b),k(c)}function j(a,b){var c=a[0];if(1===a.length)return i.call(this,c,b);var d,e=a.slice(1),f=this[c];if("object"==typeof f&&null!==f&&"function"==typeof f.setIn)d=f.setIn(e,b);else{var g=e[0];d=""!==g&&isFinite(g)?j.call(M,e,b):u.call(N,e,b)}if(c in this&&f===d)return this;var h=p.call(this);return h[c]=d,k(h)}function k(b){for(var c in K)if(K.hasOwnProperty(c)){var d=K[c];h(b,d)}a(b,"flatMap",n),a(b,"asObject",q),a(b,"asMutable",p),a(b,"set",i),a(b,"setIn",j),a(b,"update",w),a(b,"updateIn",y);for(var e=0,f=b.length;f>e;e++)b[e]=D(b[e]);return g(b,J)}function l(b){return a(b,"asMutable",m),g(b,L)}function m(){return new Date(this.getTime())}function n(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return k(c)}function o(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return-1!==b.indexOf(c)}}var c=this.instantiateEmptyObject();for(var d in this)this.hasOwnProperty(d)&&a(this[d],d)===!1&&(c[d]=this[d]);return B(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function p(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(r(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function q(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return B(c)}function r(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,G)||a instanceof Date?a:a.asMutable({deep:!0})}function s(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function t(a,b){function c(a,c,f){var g=D(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==d||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&e(k)&&e(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===d&&(d=s(a,a.instantiateEmptyObject())),d[f]=l)}}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var d,f,g=Array.isArray(a),h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(this,k,f)}else for(f in a)Object.getOwnPropertyDescriptor(a,f)&&c(this,a,f);return void 0===d?this:B(d,{instantiateEmptyObject:this.instantiateEmptyObject})}function u(a,b){var c=a[0];if(1===a.length)return v.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):u.call(N,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=s(this,this.instantiateEmptyObject());return g[c]=d,B(g,this)}function v(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=s(this,this.instantiateEmptyObject());return c[a]=D(b),B(c,this)}function w(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return this.set(a,b.apply(d,[d].concat(c)))}function x(a,b){for(var c=0,d=b.length;null!=a&&d>c;c++)a=a[b[c]];return c&&c==d?a:void 0}function y(a,b){var c=Array.prototype.slice.call(arguments,2),d=x(this,a);return this.setIn(a,b.apply(d,[d].concat(c)))}function z(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=r(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function A(){return{}}function B(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:A;return a(b,"merge",t),a(b,"without",o),a(b,"asMutable",z),a(b,"instantiateEmptyObject",d),a(b,"set",v),a(b,"setIn",u),a(b,"update",w),a(b,"updateIn",y),g(b,H)}function C(a){return"object"==typeof a&&null!==a&&(a.$$typeof===F||a.$$typeof===E)}function D(a,b,c){if(d(a)||C(a))return a;if(Array.isArray(a))return k(a.slice());if(a instanceof Date)return l(new Date(a.getTime()));var e=b&&b.prototype,g=e&&e!==Object.prototype?function(){return Object.create(e)}:A,h=g();if(null==c&&(c=64),0>=c)throw new f("Attempt to construct Immutable from a deeply nested object was detected. Have you tried to wrap an object with circular references (e.g. React element)? See https://github.com/rtfeldman/seamless-immutable/wiki/Deeply-nested-object-was-detected for details.");c-=1;for(var i in a)Object.getOwnPropertyDescriptor(a,i)&&(h[i]=D(a[i],void 0,c));return B(h,{instantiateEmptyObject:g})}var E="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),F=60103,G="__immutable_invariants_hold",H=["setPrototypeOf"],I=["keys"],J=H.concat(["push","pop","sort","splice","shift","unshift","reverse"]),K=I.concat(["map","filter","slice","concat","reduce","reduceRight"]),L=H.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);f.prototype=Error.prototype;var M=D([]),N=D({});D.from=D,D.isImmutable=d,D.ImmutableError=f,Object.freeze(D),"object"==typeof module?module.exports=D:"object"==typeof exports?exports.Immutable=D:"object"==typeof window?window.Immutable=D:"object"==typeof global&&(global.Immutable=D)}();
\ No newline at end of file
+/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b,c){a(b,c,function(){throw new f("The "+c+" method cannot be invoked on an Immutable data structure.")})}function c(b){a(b,G,!0)}function d(a){return"object"!=typeof a||(null===a||Boolean(Object.getOwnPropertyDescriptor(a,G)))}function e(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function f(a){var b=new Error(a);return b.__proto__=f,b}function g(a,d){c(a);for(var e in d)d.hasOwnProperty(e)&&b(a,d[e]);return Object.freeze(a),a}function h(b,c){var d=b[c];a(b,c,function(){return D(d.apply(b,arguments))})}function i(a,b){if(a in this&&this[a]===b)return this;var c=p.call(this);return c[a]=D(b),k(c)}function j(a,b){var c=a[0];if(1===a.length)return i.call(this,c,b);var d,e=a.slice(1),f=this[c];if("object"==typeof f&&null!==f&&"function"==typeof f.setIn)d=f.setIn(e,b);else{var g=e[0];d=""!==g&&isFinite(g)?j.call(M,e,b):u.call(N,e,b)}if(c in this&&f===d)return this;var h=p.call(this);return h[c]=d,k(h)}function k(b){for(var c in K)if(K.hasOwnProperty(c)){var d=K[c];h(b,d)}a(b,"flatMap",n),a(b,"asObject",q),a(b,"asMutable",p),a(b,"set",i),a(b,"setIn",j),a(b,"update",w),a(b,"updateIn",y);for(var e=0,f=b.length;e<f;e++)b[e]=D(b[e]);return g(b,J)}function l(b){return a(b,"asMutable",m),g(b,L)}function m(){return new Date(this.getTime())}function n(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return k(c)}function o(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return b.indexOf(c)!==-1}}var c=this.instantiateEmptyObject();for(var d in this)this.hasOwnProperty(d)&&a(this[d],d)===!1&&(c[d]=this[d]);return B(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function p(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;b<c;b++)d.push(r(this[b]));else for(b=0,c=this.length;b<c;b++)d.push(this[b]);return d}function q(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return B(c)}function r(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,G)||a instanceof Date?a:a.asMutable({deep:!0})}function s(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function t(a,b){function c(a,c,f){var g=D(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==d||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&e(k)&&e(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===d&&(d=s(a,a.instantiateEmptyObject())),d[f]=l)}}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var d,f,g=Array.isArray(a),h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(void 0!==d?d:this,k,f)}else for(f in a)Object.getOwnPropertyDescriptor(a,f)&&c(this,a,f);return void 0===d?this:B(d,{instantiateEmptyObject:this.instantiateEmptyObject})}function u(a,b){var c=a[0];if(1===a.length)return v.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):u.call(N,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=s(this,this.instantiateEmptyObject());return g[c]=d,B(g,this)}function v(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=s(this,this.instantiateEmptyObject());return c[a]=D(b),B(c,this)}function w(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return this.set(a,b.apply(d,[d].concat(c)))}function x(a,b){for(var c=0,d=b.length;null!=a&&c<d;c++)a=a[b[c]];return c&&c==d?a:void 0}function y(a,b){var c=Array.prototype.slice.call(arguments,2),d=x(this,a);return this.setIn(a,b.apply(d,[d].concat(c)))}function z(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=r(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function A(){return{}}function B(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:A;return a(b,"merge",t),a(b,"without",o),a(b,"asMutable",z),a(b,"instantiateEmptyObject",d),a(b,"set",v),a(b,"setIn",u),a(b,"update",w),a(b,"updateIn",y),g(b,H)}function C(a){return"object"==typeof a&&null!==a&&(a.$$typeof===F||a.$$typeof===E)}function D(a,b,c){if(d(a)||C(a))return a;if(Array.isArray(a))return k(a.slice());if(a instanceof Date)return l(new Date(a.getTime()));var e=b&&b.prototype,g=e&&e!==Object.prototype?function(){return Object.create(e)}:A,h=g();if(null==c&&(c=64),c<=0)throw new f("Attempt to construct Immutable from a deeply nested object was detected. Have you tried to wrap an object with circular references (e.g. React element)? See https://github.com/rtfeldman/seamless-immutable/wiki/Deeply-nested-object-was-detected for details.");c-=1;for(var i in a)Object.getOwnPropertyDescriptor(a,i)&&(h[i]=D(a[i],void 0,c));return B(h,{instantiateEmptyObject:g})}var E="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),F=60103,G="__immutable_invariants_hold",H=["setPrototypeOf"],I=["keys"],J=H.concat(["push","pop","sort","splice","shift","unshift","reverse"]),K=I.concat(["map","filter","slice","concat","reduce","reduceRight"]),L=H.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);f.prototype=Error.prototype;var M=D([]),N=D({});D.from=D,D.isImmutable=d,D.ImmutableError=f,Object.freeze(D),"object"==typeof module?module.exports=D:"object"==typeof exports?exports.Immutable=D:"object"==typeof window?window.Immutable=D:"object"==typeof global&&(global.Immutable=D)}();
\ No newline at end of file
diff --git a/seamless-immutable.production.min.js b/seamless-immutable.production.min.js
index 034e603..8616937 100644
--- a/seamless-immutable.production.min.js
+++ b/seamless-immutable.production.min.js
@@ -1,1 +1,1 @@
-/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b){a(b,F,!0)}function c(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,F)):!0}function d(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function e(a){var b=new Error(a);return b.__proto__=e,b}function f(a,c){b(a);return a}function g(b,c){var d=b[c];a(b,c,function(){return C(d.apply(b,arguments))})}function h(a,b){if(a in this&&this[a]===b)return this;var c=o.call(this);return c[a]=C(b),j(c)}function i(a,b){var c=a[0];if(1===a.length)return h.call(this,c,b);var d,e=a.slice(1),f=this[c];if("object"==typeof f&&null!==f&&"function"==typeof f.setIn)d=f.setIn(e,b);else{var g=e[0];d=""!==g&&isFinite(g)?i.call(L,e,b):t.call(M,e,b)}if(c in this&&f===d)return this;var k=o.call(this);return k[c]=d,j(k)}function j(b){for(var c in J)if(J.hasOwnProperty(c)){var d=J[c];g(b,d)}a(b,"flatMap",m),a(b,"asObject",p),a(b,"asMutable",o),a(b,"set",h),a(b,"setIn",i),a(b,"update",v),a(b,"updateIn",x);for(var e=0,j=b.length;j>e;e++)b[e]=C(b[e]);return f(b,I)}function k(b){return a(b,"asMutable",l),f(b,K)}function l(){return new Date(this.getTime())}function m(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return j(c)}function n(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return-1!==b.indexOf(c)}}var c=this.instantiateEmptyObject();for(var d in this)this.hasOwnProperty(d)&&a(this[d],d)===!1&&(c[d]=this[d]);return A(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function o(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(q(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function p(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return A(c)}function q(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,F)||a instanceof Date?a:a.asMutable({deep:!0})}function r(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function s(a,b){function c(a,c,f){var g=C(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==e||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&d(k)&&d(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===e&&(e=r(a,a.instantiateEmptyObject())),e[f]=l)}}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var e,f,g=Array.isArray(a),h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(this,k,f)}else for(f in a)Object.getOwnPropertyDescriptor(a,f)&&c(this,a,f);return void 0===e?this:A(e,{instantiateEmptyObject:this.instantiateEmptyObject})}function t(a,b){var c=a[0];if(1===a.length)return u.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):t.call(M,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=r(this,this.instantiateEmptyObject());return g[c]=d,A(g,this)}function u(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=r(this,this.instantiateEmptyObject());return c[a]=C(b),A(c,this)}function v(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return this.set(a,b.apply(d,[d].concat(c)))}function w(a,b){for(var c=0,d=b.length;null!=a&&d>c;c++)a=a[b[c]];return c&&c==d?a:void 0}function x(a,b){var c=Array.prototype.slice.call(arguments,2),d=w(this,a);return this.setIn(a,b.apply(d,[d].concat(c)))}function y(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=q(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function z(){return{}}function A(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:z;return a(b,"merge",s),a(b,"without",n),a(b,"asMutable",y),a(b,"instantiateEmptyObject",d),a(b,"set",u),a(b,"setIn",t),a(b,"update",v),a(b,"updateIn",x),f(b,G)}function B(a){return"object"==typeof a&&null!==a&&(a.$$typeof===E||a.$$typeof===D)}function C(a,b,d){if(c(a)||B(a))return a;if(Array.isArray(a))return j(a.slice());if(a instanceof Date)return k(new Date(a.getTime()));var e=b&&b.prototype,f=e&&e!==Object.prototype?function(){return Object.create(e)}:z,g=f();for(var h in a)Object.getOwnPropertyDescriptor(a,h)&&(g[h]=C(a[h],void 0,d));return A(g,{instantiateEmptyObject:f})}var D="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),E=60103,F="__immutable_invariants_hold",G=["setPrototypeOf"],H=["keys"],I=G.concat(["push","pop","sort","splice","shift","unshift","reverse"]),J=H.concat(["map","filter","slice","concat","reduce","reduceRight"]),K=G.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);e.prototype=Error.prototype;var L=C([]),M=C({});C.from=C,C.isImmutable=c,C.ImmutableError=e,Object.freeze(C),"object"==typeof module?module.exports=C:"object"==typeof exports?exports.Immutable=C:"object"==typeof window?window.Immutable=C:"object"==typeof global&&(global.Immutable=C)}();
\ No newline at end of file
+/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b){a(b,F,!0)}function c(a){return"object"!=typeof a||(null===a||Boolean(Object.getOwnPropertyDescriptor(a,F)))}function d(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function e(a){var b=new Error(a);return b.__proto__=e,b}function f(a,c){b(a);return a}function g(b,c){var d=b[c];a(b,c,function(){return C(d.apply(b,arguments))})}function h(a,b){if(a in this&&this[a]===b)return this;var c=o.call(this);return c[a]=C(b),j(c)}function i(a,b){var c=a[0];if(1===a.length)return h.call(this,c,b);var d,e=a.slice(1),f=this[c];if("object"==typeof f&&null!==f&&"function"==typeof f.setIn)d=f.setIn(e,b);else{var g=e[0];d=""!==g&&isFinite(g)?i.call(L,e,b):t.call(M,e,b)}if(c in this&&f===d)return this;var k=o.call(this);return k[c]=d,j(k)}function j(b){for(var c in J)if(J.hasOwnProperty(c)){var d=J[c];g(b,d)}a(b,"flatMap",m),a(b,"asObject",p),a(b,"asMutable",o),a(b,"set",h),a(b,"setIn",i),a(b,"update",v),a(b,"updateIn",x);for(var e=0,j=b.length;e<j;e++)b[e]=C(b[e]);return f(b,I)}function k(b){return a(b,"asMutable",l),f(b,K)}function l(){return new Date(this.getTime())}function m(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return j(c)}function n(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return b.indexOf(c)!==-1}}var c=this.instantiateEmptyObject();for(var d in this)this.hasOwnProperty(d)&&a(this[d],d)===!1&&(c[d]=this[d]);return A(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function o(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;b<c;b++)d.push(q(this[b]));else for(b=0,c=this.length;b<c;b++)d.push(this[b]);return d}function p(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return A(c)}function q(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,F)||a instanceof Date?a:a.asMutable({deep:!0})}function r(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function s(a,b){function c(a,c,f){var g=C(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==e||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&d(k)&&d(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===e&&(e=r(a,a.instantiateEmptyObject())),e[f]=l)}}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var e,f,g=Array.isArray(a),h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(void 0!==e?e:this,k,f)}else for(f in a)Object.getOwnPropertyDescriptor(a,f)&&c(this,a,f);return void 0===e?this:A(e,{instantiateEmptyObject:this.instantiateEmptyObject})}function t(a,b){var c=a[0];if(1===a.length)return u.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):t.call(M,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=r(this,this.instantiateEmptyObject());return g[c]=d,A(g,this)}function u(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=r(this,this.instantiateEmptyObject());return c[a]=C(b),A(c,this)}function v(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return this.set(a,b.apply(d,[d].concat(c)))}function w(a,b){for(var c=0,d=b.length;null!=a&&c<d;c++)a=a[b[c]];return c&&c==d?a:void 0}function x(a,b){var c=Array.prototype.slice.call(arguments,2),d=w(this,a);return this.setIn(a,b.apply(d,[d].concat(c)))}function y(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=q(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function z(){return{}}function A(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:z;return a(b,"merge",s),a(b,"without",n),a(b,"asMutable",y),a(b,"instantiateEmptyObject",d),a(b,"set",u),a(b,"setIn",t),a(b,"update",v),a(b,"updateIn",x),f(b,G)}function B(a){return"object"==typeof a&&null!==a&&(a.$$typeof===E||a.$$typeof===D)}function C(a,b,d){if(c(a)||B(a))return a;if(Array.isArray(a))return j(a.slice());if(a instanceof Date)return k(new Date(a.getTime()));var e=b&&b.prototype,f=e&&e!==Object.prototype?function(){return Object.create(e)}:z,g=f();for(var h in a)Object.getOwnPropertyDescriptor(a,h)&&(g[h]=C(a[h],void 0,d));return A(g,{instantiateEmptyObject:f})}var D="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),E=60103,F="__immutable_invariants_hold",G=["setPrototypeOf"],H=["keys"],I=G.concat(["push","pop","sort","splice","shift","unshift","reverse"]),J=H.concat(["map","filter","slice","concat","reduce","reduceRight"]),K=G.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);e.prototype=Error.prototype;var L=C([]),M=C({});C.from=C,C.isImmutable=c,C.ImmutableError=e,Object.freeze(C),"object"==typeof module?module.exports=C:"object"==typeof exports?exports.Immutable=C:"object"==typeof window?window.Immutable=C:"object"==typeof global&&(global.Immutable=C)}();
\ No newline at end of file
diff --git a/src/seamless-immutable.js b/src/seamless-immutable.js
index b38651c..b88a073 100644
--- a/src/seamless-immutable.js
+++ b/src/seamless-immutable.js
@@ -398,7 +398,7 @@
 
         for (key in otherFromArray) {
           if (otherFromArray.hasOwnProperty(key)) {
-            addToResult(this, otherFromArray, key);
+            addToResult(result !== undefined ? result : this, otherFromArray, key);
           }
         }
       }


Test patch:
diff --git a/test/ImmutableObject/test-merge.js b/test/ImmutableObject/test-merge.js
index 9b2f51d..5ab2189 100644
--- a/test/ImmutableObject/test-merge.js
+++ b/test/ImmutableObject/test-merge.js
@@ -211,6 +211,21 @@ module.exports = function(config) {
       TestUtils.assertJsonEqual(actualDeep, expectedDeep);
     });
 
+    it("merges deep when the config tells it to with an array as the first argument", function() {
+      var original = Immutable({test: {a: true}});
+      var toMerge  = [{test: {b: true}}, {test: {c: true}}];
+
+      var expectedShallow = Immutable({test: {c: true}});
+      var actualShallow   = original.merge(toMerge);
+
+      TestUtils.assertJsonEqual(actualShallow, expectedShallow);
+
+      var expectedDeep = Immutable({test: {a: true, b: true, c: true}});
+      var actualDeep   = original.merge(toMerge, {deep: true});
+
+      TestUtils.assertJsonEqual(actualDeep, expectedDeep);
+    });
+
     it("merges deep on only objects", function() {
       var original = Immutable({id: 3, name: "three", valid: true, a: {id: 2}, b: [50], x: [1, 2], sub: {z: [100]}});
       var toMerge = {id: 3, name: "three", valid: false, a: [1000], b: {id: 4}, x: [3, 4], sub: {y: [10, 11], z: [101, 102]}};