@most/prelude
Advanced tools
Comparing version 1.6.4 to 1.7.0
@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
// a with x prepended | ||
function cons (x, a) { | ||
function cons(x, a) { | ||
var l = a.length; | ||
@@ -15,3 +15,3 @@ var b = new Array(l + 1); | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -21,3 +21,3 @@ | ||
// a with x appended | ||
function append (x, a) { | ||
function append(x, a) { | ||
var l = a.length; | ||
@@ -30,3 +30,3 @@ var b = new Array(l + 1); | ||
b[l] = x; | ||
return b | ||
return b; | ||
} | ||
@@ -36,5 +36,6 @@ | ||
// drop first n elements | ||
function drop (n, a) { // eslint-disable-line complexity | ||
function drop(n, a) { | ||
// eslint-disable-line complexity | ||
if (n < 0) { | ||
throw new TypeError('n must be >= 0') | ||
throw new TypeError('n must be >= 0'); | ||
} | ||
@@ -44,10 +45,10 @@ | ||
if (n === 0 || l === 0) { | ||
return a | ||
return a; | ||
} | ||
if (n >= l) { | ||
return [] | ||
return []; | ||
} | ||
return unsafeDrop(n, a, l - n) | ||
return unsafeDrop(n, a, l - n); | ||
} | ||
@@ -57,3 +58,3 @@ | ||
// Internal helper for drop | ||
function unsafeDrop (n, a, l) { | ||
function unsafeDrop(n, a, l) { | ||
var b = new Array(l); | ||
@@ -63,3 +64,3 @@ for (var i = 0; i < l; ++i) { | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -69,4 +70,4 @@ | ||
// drop head element | ||
function tail (a) { | ||
return drop(1, a) | ||
function tail(a) { | ||
return drop(1, a); | ||
} | ||
@@ -76,3 +77,3 @@ | ||
// duplicate a (shallow duplication) | ||
function copy (a) { | ||
function copy(a) { | ||
var l = a.length; | ||
@@ -83,3 +84,3 @@ var b = new Array(l); | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -89,3 +90,3 @@ | ||
// transform each element with f | ||
function map (f, a) { | ||
function map(f, a) { | ||
var l = a.length; | ||
@@ -96,3 +97,3 @@ var b = new Array(l); | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -102,3 +103,3 @@ | ||
// accumulate via left-fold | ||
function reduce (f, z, a) { | ||
function reduce(f, z, a) { | ||
var r = z; | ||
@@ -108,3 +109,3 @@ for (var i = 0, l = a.length; i < l; ++i) { | ||
} | ||
return r | ||
return r; | ||
} | ||
@@ -114,5 +115,6 @@ | ||
// replace element at index | ||
function replace (x, i, a) { // eslint-disable-line complexity | ||
function replace(x, i, a) { | ||
// eslint-disable-line complexity | ||
if (i < 0) { | ||
throw new TypeError('i must be >= 0') | ||
throw new TypeError('i must be >= 0'); | ||
} | ||
@@ -125,3 +127,3 @@ | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -131,17 +133,20 @@ | ||
// remove element at index | ||
function remove (i, a) { // eslint-disable-line complexity | ||
function remove(i, a) { | ||
// eslint-disable-line complexity | ||
if (i < 0) { | ||
throw new TypeError('i must be >= 0') | ||
throw new TypeError('i must be >= 0'); | ||
} | ||
var l = a.length; | ||
if (l === 0 || i >= l) { // exit early if index beyond end of array | ||
return a | ||
if (l === 0 || i >= l) { | ||
// exit early if index beyond end of array | ||
return a; | ||
} | ||
if (l === 1) { // exit early if index in bounds and length === 1 | ||
return [] | ||
if (l === 1) { | ||
// exit early if index in bounds and length === 1 | ||
return []; | ||
} | ||
return unsafeRemove(i, a, l - 1) | ||
return unsafeRemove(i, a, l - 1); | ||
} | ||
@@ -151,5 +156,5 @@ | ||
// Internal helper to remove element at index | ||
function unsafeRemove (i, a, l) { | ||
function unsafeRemove(i, a, l) { | ||
var b = new Array(l); | ||
var j; | ||
var j = void 0; | ||
for (j = 0; j < i; ++j) { | ||
@@ -162,3 +167,3 @@ b[j] = a[j]; | ||
return b | ||
return b; | ||
} | ||
@@ -168,7 +173,7 @@ | ||
// remove all elements matching a predicate | ||
function removeAll (f, a) { | ||
function removeAll(f, a) { | ||
var l = a.length; | ||
var b = new Array(l); | ||
var j = 0; | ||
for (var x = (void 0), i = 0; i < l; ++i) { | ||
for (var x, i = 0; i < l; ++i) { | ||
x = a[i]; | ||
@@ -182,3 +187,3 @@ if (!f(x)) { | ||
b.length = j; | ||
return b | ||
return b; | ||
} | ||
@@ -188,9 +193,9 @@ | ||
// find index of x in a, from the left | ||
function findIndex (x, a) { | ||
function findIndex(x, a) { | ||
for (var i = 0, l = a.length; i < l; ++i) { | ||
if (x === a[i]) { | ||
return i | ||
return i; | ||
} | ||
} | ||
return -1 | ||
return -1; | ||
} | ||
@@ -200,4 +205,4 @@ | ||
// Return true iff x is array-like | ||
function isArrayLike (x) { | ||
return x != null && typeof x.length === 'number' && typeof x !== 'function' | ||
function isArrayLike(x) { | ||
return x != null && typeof x.length === 'number' && typeof x !== 'function'; | ||
} | ||
@@ -208,47 +213,81 @@ | ||
// id :: a -> a | ||
var id = function (x) { return x; }; | ||
var id = function id(x) { | ||
return x; | ||
}; | ||
// compose :: (b -> c) -> (a -> b) -> (a -> c) | ||
var compose = function (f, g) { return function (x) { return f(g(x)); }; }; | ||
var compose = function compose(f, g) { | ||
return function (x) { | ||
return f(g(x)); | ||
}; | ||
}; | ||
// apply :: (a -> b) -> a -> b | ||
var apply = function (f, x) { return f(x); }; | ||
var apply = function apply(f, x) { | ||
return f(x); | ||
}; | ||
// curry2 :: ((a, b) -> c) -> (a -> b -> c) | ||
function curry2 (f) { | ||
function curried (a, b) { | ||
function curry2(f) { | ||
function curried(a, b) { | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return function (b) { return f(a, b); } | ||
default: return f(a, b) | ||
case 0: | ||
return curried; | ||
case 1: | ||
return function (b) { | ||
return f(a, b); | ||
}; | ||
default: | ||
return f(a, b); | ||
} | ||
} | ||
return curried | ||
return curried; | ||
} | ||
// curry3 :: ((a, b, c) -> d) -> (a -> b -> c -> d) | ||
function curry3 (f) { | ||
function curried (a, b, c) { // eslint-disable-line complexity | ||
function curry3(f) { | ||
function curried(a, b, c) { | ||
// eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry2(function (b, c) { return f(a, b, c); }) | ||
case 2: return function (c) { return f(a, b, c); } | ||
default:return f(a, b, c) | ||
case 0: | ||
return curried; | ||
case 1: | ||
return curry2(function (b, c) { | ||
return f(a, b, c); | ||
}); | ||
case 2: | ||
return function (c) { | ||
return f(a, b, c); | ||
}; | ||
default: | ||
return f(a, b, c); | ||
} | ||
} | ||
return curried | ||
return curried; | ||
} | ||
// curry4 :: ((a, b, c, d) -> e) -> (a -> b -> c -> d -> e) | ||
function curry4 (f) { | ||
function curried (a, b, c, d) { // eslint-disable-line complexity | ||
function curry4(f) { | ||
function curried(a, b, c, d) { | ||
// eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry3(function (b, c, d) { return f(a, b, c, d); }) | ||
case 2: return curry2(function (c, d) { return f(a, b, c, d); }) | ||
case 3: return function (d) { return f(a, b, c, d); } | ||
default:return f(a, b, c, d) | ||
case 0: | ||
return curried; | ||
case 1: | ||
return curry3(function (b, c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
case 2: | ||
return curry2(function (c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
case 3: | ||
return function (d) { | ||
return f(a, b, c, d); | ||
}; | ||
default: | ||
return f(a, b, c, d); | ||
} | ||
} | ||
return curried | ||
return curried; | ||
} | ||
@@ -255,0 +294,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.mostPrelude = global.mostPrelude || {}))); | ||
(factory((global.mostPrelude = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -13,3 +13,3 @@ | ||
// a with x prepended | ||
function cons (x, a) { | ||
function cons(x, a) { | ||
var l = a.length; | ||
@@ -21,3 +21,3 @@ var b = new Array(l + 1); | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -27,3 +27,3 @@ | ||
// a with x appended | ||
function append (x, a) { | ||
function append(x, a) { | ||
var l = a.length; | ||
@@ -36,3 +36,3 @@ var b = new Array(l + 1); | ||
b[l] = x; | ||
return b | ||
return b; | ||
} | ||
@@ -42,5 +42,6 @@ | ||
// drop first n elements | ||
function drop (n, a) { // eslint-disable-line complexity | ||
function drop(n, a) { | ||
// eslint-disable-line complexity | ||
if (n < 0) { | ||
throw new TypeError('n must be >= 0') | ||
throw new TypeError('n must be >= 0'); | ||
} | ||
@@ -50,10 +51,10 @@ | ||
if (n === 0 || l === 0) { | ||
return a | ||
return a; | ||
} | ||
if (n >= l) { | ||
return [] | ||
return []; | ||
} | ||
return unsafeDrop(n, a, l - n) | ||
return unsafeDrop(n, a, l - n); | ||
} | ||
@@ -63,3 +64,3 @@ | ||
// Internal helper for drop | ||
function unsafeDrop (n, a, l) { | ||
function unsafeDrop(n, a, l) { | ||
var b = new Array(l); | ||
@@ -69,3 +70,3 @@ for (var i = 0; i < l; ++i) { | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -75,4 +76,4 @@ | ||
// drop head element | ||
function tail (a) { | ||
return drop(1, a) | ||
function tail(a) { | ||
return drop(1, a); | ||
} | ||
@@ -82,3 +83,3 @@ | ||
// duplicate a (shallow duplication) | ||
function copy (a) { | ||
function copy(a) { | ||
var l = a.length; | ||
@@ -89,3 +90,3 @@ var b = new Array(l); | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -95,3 +96,3 @@ | ||
// transform each element with f | ||
function map (f, a) { | ||
function map(f, a) { | ||
var l = a.length; | ||
@@ -102,3 +103,3 @@ var b = new Array(l); | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -108,3 +109,3 @@ | ||
// accumulate via left-fold | ||
function reduce (f, z, a) { | ||
function reduce(f, z, a) { | ||
var r = z; | ||
@@ -114,3 +115,3 @@ for (var i = 0, l = a.length; i < l; ++i) { | ||
} | ||
return r | ||
return r; | ||
} | ||
@@ -120,5 +121,6 @@ | ||
// replace element at index | ||
function replace (x, i, a) { // eslint-disable-line complexity | ||
function replace(x, i, a) { | ||
// eslint-disable-line complexity | ||
if (i < 0) { | ||
throw new TypeError('i must be >= 0') | ||
throw new TypeError('i must be >= 0'); | ||
} | ||
@@ -131,3 +133,3 @@ | ||
} | ||
return b | ||
return b; | ||
} | ||
@@ -137,17 +139,20 @@ | ||
// remove element at index | ||
function remove (i, a) { // eslint-disable-line complexity | ||
function remove(i, a) { | ||
// eslint-disable-line complexity | ||
if (i < 0) { | ||
throw new TypeError('i must be >= 0') | ||
throw new TypeError('i must be >= 0'); | ||
} | ||
var l = a.length; | ||
if (l === 0 || i >= l) { // exit early if index beyond end of array | ||
return a | ||
if (l === 0 || i >= l) { | ||
// exit early if index beyond end of array | ||
return a; | ||
} | ||
if (l === 1) { // exit early if index in bounds and length === 1 | ||
return [] | ||
if (l === 1) { | ||
// exit early if index in bounds and length === 1 | ||
return []; | ||
} | ||
return unsafeRemove(i, a, l - 1) | ||
return unsafeRemove(i, a, l - 1); | ||
} | ||
@@ -157,5 +162,5 @@ | ||
// Internal helper to remove element at index | ||
function unsafeRemove (i, a, l) { | ||
function unsafeRemove(i, a, l) { | ||
var b = new Array(l); | ||
var j; | ||
var j = void 0; | ||
for (j = 0; j < i; ++j) { | ||
@@ -168,3 +173,3 @@ b[j] = a[j]; | ||
return b | ||
return b; | ||
} | ||
@@ -174,7 +179,7 @@ | ||
// remove all elements matching a predicate | ||
function removeAll (f, a) { | ||
function removeAll(f, a) { | ||
var l = a.length; | ||
var b = new Array(l); | ||
var j = 0; | ||
for (var x = (void 0), i = 0; i < l; ++i) { | ||
for (var x, i = 0; i < l; ++i) { | ||
x = a[i]; | ||
@@ -188,3 +193,3 @@ if (!f(x)) { | ||
b.length = j; | ||
return b | ||
return b; | ||
} | ||
@@ -194,9 +199,9 @@ | ||
// find index of x in a, from the left | ||
function findIndex (x, a) { | ||
function findIndex(x, a) { | ||
for (var i = 0, l = a.length; i < l; ++i) { | ||
if (x === a[i]) { | ||
return i | ||
return i; | ||
} | ||
} | ||
return -1 | ||
return -1; | ||
} | ||
@@ -206,4 +211,4 @@ | ||
// Return true iff x is array-like | ||
function isArrayLike (x) { | ||
return x != null && typeof x.length === 'number' && typeof x !== 'function' | ||
function isArrayLike(x) { | ||
return x != null && typeof x.length === 'number' && typeof x !== 'function'; | ||
} | ||
@@ -214,47 +219,81 @@ | ||
// id :: a -> a | ||
var id = function (x) { return x; }; | ||
var id = function id(x) { | ||
return x; | ||
}; | ||
// compose :: (b -> c) -> (a -> b) -> (a -> c) | ||
var compose = function (f, g) { return function (x) { return f(g(x)); }; }; | ||
var compose = function compose(f, g) { | ||
return function (x) { | ||
return f(g(x)); | ||
}; | ||
}; | ||
// apply :: (a -> b) -> a -> b | ||
var apply = function (f, x) { return f(x); }; | ||
var apply = function apply(f, x) { | ||
return f(x); | ||
}; | ||
// curry2 :: ((a, b) -> c) -> (a -> b -> c) | ||
function curry2 (f) { | ||
function curried (a, b) { | ||
function curry2(f) { | ||
function curried(a, b) { | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return function (b) { return f(a, b); } | ||
default: return f(a, b) | ||
case 0: | ||
return curried; | ||
case 1: | ||
return function (b) { | ||
return f(a, b); | ||
}; | ||
default: | ||
return f(a, b); | ||
} | ||
} | ||
return curried | ||
return curried; | ||
} | ||
// curry3 :: ((a, b, c) -> d) -> (a -> b -> c -> d) | ||
function curry3 (f) { | ||
function curried (a, b, c) { // eslint-disable-line complexity | ||
function curry3(f) { | ||
function curried(a, b, c) { | ||
// eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry2(function (b, c) { return f(a, b, c); }) | ||
case 2: return function (c) { return f(a, b, c); } | ||
default:return f(a, b, c) | ||
case 0: | ||
return curried; | ||
case 1: | ||
return curry2(function (b, c) { | ||
return f(a, b, c); | ||
}); | ||
case 2: | ||
return function (c) { | ||
return f(a, b, c); | ||
}; | ||
default: | ||
return f(a, b, c); | ||
} | ||
} | ||
return curried | ||
return curried; | ||
} | ||
// curry4 :: ((a, b, c, d) -> e) -> (a -> b -> c -> d -> e) | ||
function curry4 (f) { | ||
function curried (a, b, c, d) { // eslint-disable-line complexity | ||
function curry4(f) { | ||
function curried(a, b, c, d) { | ||
// eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry3(function (b, c, d) { return f(a, b, c, d); }) | ||
case 2: return curry2(function (c, d) { return f(a, b, c, d); }) | ||
case 3: return function (d) { return f(a, b, c, d); } | ||
default:return f(a, b, c, d) | ||
case 0: | ||
return curried; | ||
case 1: | ||
return curry3(function (b, c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
case 2: | ||
return curry2(function (c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
case 3: | ||
return function (d) { | ||
return f(a, b, c, d); | ||
}; | ||
default: | ||
return f(a, b, c, d); | ||
} | ||
} | ||
return curried | ||
return curried; | ||
} | ||
@@ -261,0 +300,0 @@ |
{ | ||
"name": "@most/prelude", | ||
"version": "1.6.4", | ||
"version": "1.7.0", | ||
"description": "prelude", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"jsnext:main": "dist/index.es.js", | ||
"typings": "type-definitions/index.d.ts", | ||
@@ -16,7 +15,7 @@ "files": [ | ||
"build:dist": "rollup -c", | ||
"build:flow": "cpy src/index.js.flow dist && cpy src/index.js.flow dist --rename=index.es.js.flow", | ||
"prepublish": "npm run build", | ||
"build:flow": "cpy src/index.js.flow dist", | ||
"prepare": "npm run build", | ||
"test": "npm run test:lint && npm run test:unit && npm run test:flow", | ||
"test:lint": "standard --fix 'src/**/*.js' 'test/**/*.js' --verbose | snazzy", | ||
"test:unit": "nyc --reporter=text-summary mocha -r buba/register --reporter dot", | ||
"test:unit": "cross-env NODE_ENV=test nyc --reporter=text-summary mocha -r babel-register --reporter dot", | ||
"test:flow": "flow check" | ||
@@ -35,10 +34,13 @@ }, | ||
"devDependencies": { | ||
"babel-preset-power-assert": "^1.0.0", | ||
"buba": "^4.0.2", | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-annotate-pure-calls": "^0.2.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-register": "^6.26.0", | ||
"cpy-cli": "^1.0.1", | ||
"flow-bin": "^0.53.1", | ||
"cross-env": "^5.0.5", | ||
"flow-bin": "^0.57.3", | ||
"mocha": "^3.4.2", | ||
"nyc": "^11.0.2", | ||
"rollup": "^0.43.0", | ||
"rollup-plugin-buble": "^0.15.0", | ||
"rollup": "^0.50.0", | ||
"snazzy": "^7.0.0", | ||
@@ -45,0 +47,0 @@ "standard": "^10.0.3" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
540
40438
13