From 1ccc4377f39f68f7d20c72721b0aa3854ef2712c Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 25 May 2014 13:34:14 -0400 Subject: [PATCH] Split out function gestaltUnion --- route.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/route.js b/route.js index 165be31..e42418f 100644 --- a/route.js +++ b/route.js @@ -1173,12 +1173,17 @@ function Routing(exports) { return this.mapZip(other, Math.max, straightGestaltLevelOp(union)); }; - Gestalt.prototype.union = function () { - var acc = this; - for (var i = 0; i < arguments.length; i++) { - acc = acc.union1(arguments[i]); + function gestaltUnion(gs) { + if (gs.length === 0) return emptyGestalt; + var acc = gs[0]; + for (var i = 1; i < gs.length; i++) { + acc = acc.union1(gs[i]); } return acc; + } + + Gestalt.prototype.union = function () { + return arguments.length > 0 ? this.union1(gestaltUnion(arguments)) : this; }; // Returns ls, with one level dropped, and with the remaining @@ -1309,6 +1314,7 @@ function Routing(exports) { exports.Gestalt = Gestalt; exports.simpleGestalt = simpleGestalt; exports.emptyGestalt = emptyGestalt; + exports.gestaltUnion = gestaltUnion; } if (typeof module !== 'undefined' && module.exports) {