'use strict';
module.exports = [ 'curried', 'List', 'lazy', 'Set', function (curried, List, lazy, Set) {
var Nodash = this;
function insertBy(f, x, xs) {
for (var i = 0; i < xs.length; i++) {
if (f(x, xs[i]) <= 0) {
return Nodash.concat([xs.slice(0,i), x, xs.slice(i)]);
}
}
return Nodash.append(xs, x);
}
function groupBy(p, xs) {
if (xs.length === 0) {
return [];
}
var zs = [];
var current = [xs[0]];
var last = xs[0];
for (var i = 1; i < xs.length; i++) {
if (p(xs[i], last)) {
current.push(xs[i]);
} else {
zs.push(current);
current = [xs[i]];
}
last = xs[i];
}
zs.push(current);
return Nodash.isString(xs) ? Nodash.map(Nodash.arrayToString, zs) : zs;
}
return {
and: Nodash.foldl(Nodash.AND, true),
or: Nodash.foldl(Nodash.OR, false),
sum: Nodash.foldl(Nodash.ADD, 0),
product: Nodash.foldl(Nodash.MUL, 1),
maximum: Nodash.foldl(Nodash.max, -Infinity),
minimum: Nodash.foldl(Nodash.min, +Infinity),
any: function (p, xs) {
for (var i = 0; i < xs.length; i++) {
if (p(xs[i])) {
return true;
}
}
return false;
},
all: function (p, xs) {
for (var i = 0; i < xs.length; i++) {
if (!p(xs[i])) {
return false;
}
}
return true;
},
scanl: function (f, x, xs) {
var zs = [x];
for (var i = 0; i < xs.length; i++) {
x = f(x, xs[i]);
zs.push(x);
}
return zs;
},
scanl1: function (f, xs) {
var x = xs[0];
var zs = [x];
for (var i = 1; i < xs.length; i++) {
x = f(x, xs[i]);
zs.push(x);
}
return zs;
},
scanr: function (f, x, xs) {
var zs = [x];
for (var i = xs.length - 1; i >= 0; i--) {
x = f(xs[i], x);
zs.unshift(x);
}
return zs;
},
scanr1: function (f, xs) {
var x = xs[xs.length - 1];
var zs = [x];
for (var i = xs.length - 2; i >= 0; i--) {
x = f(xs[i], x);
zs.unshift(x);
}
return zs;
},
concatMap: Nodash.compose2(Nodash.concat, Nodash.map),
replicate: function (n, x) {
var xs = [];
for (var i = 0; i < n; i++) {
xs.push(x);
}
return xs;
},
zip: Nodash.zipWith(Nodash.tuple),
zip3: Nodash.zipWith3(Nodash.tuple3),
zip4: Nodash.zipWith4(Nodash.tuple4),
intersperse: function (x, xs) {
if (xs.length === 0) {
return [];
}
var z = [xs[0]];
for (var i = 1; i < xs.length; i++) {
z.push(x);
z.push(xs[i]);
}
return z;
},
intercalate: function (x, xs) {
return Nodash.concat(Nodash.intersperse(x, xs));
},
transpose: function (xss) {
if (!Nodash.isArray(xss)) {
var zss = {};
var ks = Object.keys(xss);
for (var k = 0; k < ks.length; k++) {
zss[xss[ks[k]]] = ks[k];
}
return zss;
}
var j = 0;
var zs = [];
var current;
do {
current = [];
for (var i = 0; i < xss.length; i++) {
if (xss[i][j] !== undefined) {
current.push(xss[i][j]);
}
}
j += 1;
} while (current.length > 0 && zs.push(current));
if (Nodash.isString(xss[0])) {
zs = Nodash.map(Nodash.arrayToString, zs);
}
return zs;
},
inits: function (xs) {
var result, current, i, length;
if (Nodash.isArray(xs)) {
result = [[]];
current = [];
length = xs.length;
for (i = 0; i < length; i += 1) {
current = current.concat(xs[i]);
result.push(current);
}
return result;
}