@most/prelude
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -7,239 +7,254 @@ (function (global, factory) { | ||
/** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
/** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
// Non-mutating array operations | ||
// Non-mutating array operations | ||
// cons :: a -> [a] -> [a] | ||
// a with x prepended | ||
function cons (x, a) { | ||
var l = a.length | ||
var b = new Array(l + 1) | ||
b[0] = x | ||
for (var i = 0; i < l; ++i) { | ||
b[i + 1] = a[i] | ||
// cons :: a -> [a] -> [a] | ||
// a with x prepended | ||
function cons (x, a) { | ||
var l = a.length | ||
var b = new Array(l + 1) | ||
b[0] = x | ||
for (var i = 0; i < l; ++i) { | ||
b[i + 1] = a[i] | ||
} | ||
return b | ||
} | ||
return b | ||
} | ||
// append :: a -> [a] -> [a] | ||
// a with x appended | ||
function append (x, a) { | ||
var l = a.length | ||
var b = new Array(l + 1) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[i] | ||
} | ||
// append :: a -> [a] -> [a] | ||
// a with x appended | ||
function append (x, a) { | ||
var l = a.length | ||
var b = new Array(l + 1) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[i] | ||
} | ||
b[l] = x | ||
return b | ||
} | ||
// drop :: Int -> [a] -> [a] | ||
// drop first n elements | ||
function drop (n, a) { // eslint-disable-line complexity | ||
if (n < 0) { | ||
throw new TypeError('n must be >= 0') | ||
b[l] = x | ||
return b | ||
} | ||
var l = a.length | ||
if (n === 0 || l === 0) { | ||
return a | ||
} | ||
// drop :: Int -> [a] -> [a] | ||
// drop first n elements | ||
function drop (n, a) { // eslint-disable-line complexity | ||
if (n < 0) { | ||
throw new TypeError('n must be >= 0') | ||
} | ||
if (n >= l) { | ||
return [] | ||
} | ||
var l = a.length | ||
if (n === 0 || l === 0) { | ||
return a | ||
} | ||
return unsafeDrop(n, a, l - n) | ||
} | ||
if (n >= l) { | ||
return [] | ||
} | ||
// unsafeDrop :: Int -> [a] -> Int -> [a] | ||
// Internal helper for drop | ||
function unsafeDrop (n, a, l) { | ||
var b = new Array(l) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[n + i] | ||
return unsafeDrop(n, a, l - n) | ||
} | ||
return b | ||
} | ||
// tail :: [a] -> [a] | ||
// drop head element | ||
function tail (a) { | ||
return drop(1, a) | ||
} | ||
// copy :: [a] -> [a] | ||
// duplicate a (shallow duplication) | ||
function copy (a) { | ||
var l = a.length | ||
var b = new Array(l) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[i] | ||
// unsafeDrop :: Int -> [a] -> Int -> [a] | ||
// Internal helper for drop | ||
function unsafeDrop (n, a, l) { | ||
var b = new Array(l) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[n + i] | ||
} | ||
return b | ||
} | ||
return b | ||
} | ||
// map :: (a -> b) -> [a] -> [b] | ||
// transform each element with f | ||
function map (f, a) { | ||
var l = a.length | ||
var b = new Array(l) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = f(a[i]) | ||
// tail :: [a] -> [a] | ||
// drop head element | ||
function tail (a) { | ||
return drop(1, a) | ||
} | ||
return b | ||
} | ||
// reduce :: (a -> b -> a) -> a -> [b] -> a | ||
// accumulate via left-fold | ||
function reduce (f, z, a) { | ||
var r = z | ||
for (var i = 0, l = a.length; i < l; ++i) { | ||
r = f(r, a[i], i) | ||
// copy :: [a] -> [a] | ||
// duplicate a (shallow duplication) | ||
function copy (a) { | ||
var l = a.length | ||
var b = new Array(l) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[i] | ||
} | ||
return b | ||
} | ||
return r | ||
} | ||
// replace :: a -> Int -> [a] | ||
// replace element at index | ||
function replace (x, i, a) { // eslint-disable-line complexity | ||
if (i < 0) { | ||
throw new TypeError('i must be >= 0') | ||
// map :: (a -> b) -> [a] -> [b] | ||
// transform each element with f | ||
function map (f, a) { | ||
var l = a.length | ||
var b = new Array(l) | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = f(a[i]) | ||
} | ||
return b | ||
} | ||
var l = a.length | ||
var b = new Array(l) | ||
for (var j = 0; j < l; ++j) { | ||
b[j] = i === j ? x : a[j] | ||
// reduce :: (a -> b -> a) -> a -> [b] -> a | ||
// accumulate via left-fold | ||
function reduce (f, z, a) { | ||
var r = z | ||
for (var i = 0, l = a.length; i < l; ++i) { | ||
r = f(r, a[i], i) | ||
} | ||
return r | ||
} | ||
return b | ||
} | ||
// remove :: Int -> [a] -> [a] | ||
// remove element at index | ||
function remove (i, a) { // eslint-disable-line complexity | ||
if (i < 0) { | ||
throw new TypeError('i must be >= 0') | ||
} | ||
// replace :: a -> Int -> [a] | ||
// replace element at index | ||
function replace (x, i, a) { // eslint-disable-line complexity | ||
if (i < 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 | ||
var l = a.length | ||
var b = new Array(l) | ||
for (var j = 0; j < l; ++j) { | ||
b[j] = i === j ? x : a[j] | ||
} | ||
return b | ||
} | ||
if (l === 1) { // exit early if index in bounds and length === 1 | ||
return [] | ||
// remove :: Int -> [a] -> [a] | ||
// remove element at index | ||
function remove (i, a) { // eslint-disable-line complexity | ||
if (i < 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 === 1) { // exit early if index in bounds and length === 1 | ||
return [] | ||
} | ||
return unsafeRemove(i, a, l - 1) | ||
} | ||
return unsafeRemove(i, a, l - 1) | ||
} | ||
// unsafeRemove :: Int -> [a] -> Int -> [a] | ||
// Internal helper to remove element at index | ||
function unsafeRemove (i, a, l) { | ||
var b = new Array(l) | ||
var j | ||
for (j = 0; j < i; ++j) { | ||
b[j] = a[j] | ||
} | ||
for (j = i; j < l; ++j) { | ||
b[j] = a[j + 1] | ||
} | ||
// unsafeRemove :: Int -> [a] -> Int -> [a] | ||
// Internal helper to remove element at index | ||
function unsafeRemove (i, a, l) { | ||
var b = new Array(l) | ||
var j | ||
for (j = 0; j < i; ++j) { | ||
b[j] = a[j] | ||
return b | ||
} | ||
for (j = i; j < l; ++j) { | ||
b[j] = a[j + 1] | ||
} | ||
return b | ||
} | ||
// removeAll :: (a -> boolean) -> [a] -> [a] | ||
// remove all elements matching a predicate | ||
function removeAll (f, a) { | ||
var l = a.length | ||
var b = new Array(l) | ||
var j = 0 | ||
for (var x, i = 0; i < l; ++i) { | ||
x = a[i] | ||
if (!f(x)) { | ||
b[j] = x | ||
++j | ||
} | ||
} | ||
// removeAll :: (a -> boolean) -> [a] -> [a] | ||
// remove all elements matching a predicate | ||
function removeAll (f, a) { | ||
var l = a.length | ||
var b = new Array(l) | ||
var j = 0 | ||
for (var x, i = 0; i < l; ++i) { | ||
x = a[i] | ||
if (!f(x)) { | ||
b[j] = x | ||
++j | ||
} | ||
b.length = j | ||
return b | ||
} | ||
b.length = j | ||
return b | ||
} | ||
// findIndex :: a -> [a] -> Int | ||
// find index of x in a, from the left | ||
function findIndex (x, a) { | ||
for (var i = 0, l = a.length; i < l; ++i) { | ||
if (x === a[i]) { | ||
return i | ||
// findIndex :: a -> [a] -> Int | ||
// find index of x in a, from the left | ||
function findIndex (x, a) { | ||
for (var i = 0, l = a.length; i < l; ++i) { | ||
if (x === a[i]) { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
return -1 | ||
} | ||
// isArrayLike :: * -> boolean | ||
// Return true iff x is array-like | ||
function isArrayLike (x) { | ||
return x != null && typeof x.length === 'number' && typeof x !== 'function' | ||
} | ||
// isArrayLike :: * -> boolean | ||
// Return true iff x is array-like | ||
function isArrayLike (x) { | ||
return x != null && typeof x.length === 'number' && typeof x !== 'function' | ||
} | ||
/** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
/** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
// id :: a -> a | ||
var id = function (x) { return x; } | ||
// id :: a -> a | ||
var id = function (x) { return x; } | ||
// compose :: (b -> c) -> (a -> b) -> (a -> c) | ||
var compose = function (f, g) { return function (x) { return f(g(x)); }; } | ||
// compose :: (b -> c) -> (a -> b) -> (a -> c) | ||
var compose = function (f, g) { return function (x) { return f(g(x)); }; } | ||
// apply :: (a -> b) -> a -> b | ||
var apply = function (f, x) { return f(x); } | ||
// apply :: (a -> b) -> a -> b | ||
var apply = function (f, x) { return f(x); } | ||
// curry2 :: ((a, b) -> c) -> (a -> b -> c) | ||
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) | ||
// curry2 :: ((a, b) -> c) -> (a -> b -> c) | ||
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) | ||
} | ||
} | ||
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 | ||
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) | ||
// curry3 :: ((a, b, c) -> d) -> (a -> b -> c -> d) | ||
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) | ||
} | ||
} | ||
return curried | ||
} | ||
return curried | ||
} | ||
exports.cons = cons; | ||
exports.append = append; | ||
exports.drop = drop; | ||
exports.tail = tail; | ||
exports.copy = copy; | ||
exports.map = map; | ||
exports.reduce = reduce; | ||
exports.replace = replace; | ||
exports.remove = remove; | ||
exports.removeAll = removeAll; | ||
exports.findIndex = findIndex; | ||
exports.isArrayLike = isArrayLike; | ||
exports.id = id; | ||
exports.compose = compose; | ||
exports.apply = apply; | ||
exports.curry2 = curry2; | ||
exports.curry3 = curry3; | ||
// curry4 :: ((a, b, c, d) -> e) -> (a -> b -> c -> d -> e) | ||
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) | ||
} | ||
} | ||
return curried | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.cons = cons; | ||
exports.append = append; | ||
exports.drop = drop; | ||
exports.tail = tail; | ||
exports.copy = copy; | ||
exports.map = map; | ||
exports.reduce = reduce; | ||
exports.replace = replace; | ||
exports.remove = remove; | ||
exports.removeAll = removeAll; | ||
exports.findIndex = findIndex; | ||
exports.isArrayLike = isArrayLike; | ||
exports.id = id; | ||
exports.compose = compose; | ||
exports.apply = apply; | ||
exports.curry2 = curry2; | ||
exports.curry3 = curry3; | ||
exports.curry4 = curry4; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=prelude.js.map |
@@ -1,1 +0,1 @@ | ||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):factory(global.mostPrelude=global.mostPrelude||{})})(this,function(exports){"use strict";function cons(x,a){var l=a.length;var b=new Array(l+1);b[0]=x;for(var i=0;i<l;++i){b[i+1]=a[i]}return b}function append(x,a){var l=a.length;var b=new Array(l+1);for(var i=0;i<l;++i){b[i]=a[i]}b[l]=x;return b}function drop(n,a){if(n<0){throw new TypeError("n must be >= 0")}var l=a.length;if(n===0||l===0){return a}if(n>=l){return[]}return unsafeDrop(n,a,l-n)}function unsafeDrop(n,a,l){var b=new Array(l);for(var i=0;i<l;++i){b[i]=a[n+i]}return b}function tail(a){return drop(1,a)}function copy(a){var l=a.length;var b=new Array(l);for(var i=0;i<l;++i){b[i]=a[i]}return b}function map(f,a){var l=a.length;var b=new Array(l);for(var i=0;i<l;++i){b[i]=f(a[i])}return b}function reduce(f,z,a){var r=z;for(var i=0,l=a.length;i<l;++i){r=f(r,a[i],i)}return r}function replace(x,i,a){if(i<0){throw new TypeError("i must be >= 0")}var l=a.length;var b=new Array(l);for(var j=0;j<l;++j){b[j]=i===j?x:a[j]}return b}function remove(i,a){if(i<0){throw new TypeError("i must be >= 0")}var l=a.length;if(l===0||i>=l){return a}if(l===1){return[]}return unsafeRemove(i,a,l-1)}function unsafeRemove(i,a,l){var b=new Array(l);var j;for(j=0;j<i;++j){b[j]=a[j]}for(j=i;j<l;++j){b[j]=a[j+1]}return b}function removeAll(f,a){var l=a.length;var b=new Array(l);var j=0;for(var x,i=0;i<l;++i){x=a[i];if(!f(x)){b[j]=x;++j}}b.length=j;return b}function findIndex(x,a){for(var i=0,l=a.length;i<l;++i){if(x===a[i]){return i}}return-1}function isArrayLike(x){return x!=null&&typeof x.length==="number"&&typeof x!=="function"}var id=function(x){return x};var compose=function(f,g){return function(x){return f(g(x))}};var apply=function(f,x){return f(x)};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)}}return curried}function curry3(f){function curried(a,b,c){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)}}return curried}exports.cons=cons;exports.append=append;exports.drop=drop;exports.tail=tail;exports.copy=copy;exports.map=map;exports.reduce=reduce;exports.replace=replace;exports.remove=remove;exports.removeAll=removeAll;exports.findIndex=findIndex;exports.isArrayLike=isArrayLike;exports.id=id;exports.compose=compose;exports.apply=apply;exports.curry2=curry2;exports.curry3=curry3;Object.defineProperty(exports,"__esModule",{value:true})}); | ||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):factory(global.mostPrelude=global.mostPrelude||{})})(this,function(exports){"use strict";function cons(x,a){var l=a.length;var b=new Array(l+1);b[0]=x;for(var i=0;i<l;++i){b[i+1]=a[i]}return b}function append(x,a){var l=a.length;var b=new Array(l+1);for(var i=0;i<l;++i){b[i]=a[i]}b[l]=x;return b}function drop(n,a){if(n<0){throw new TypeError("n must be >= 0")}var l=a.length;if(n===0||l===0){return a}if(n>=l){return[]}return unsafeDrop(n,a,l-n)}function unsafeDrop(n,a,l){var b=new Array(l);for(var i=0;i<l;++i){b[i]=a[n+i]}return b}function tail(a){return drop(1,a)}function copy(a){var l=a.length;var b=new Array(l);for(var i=0;i<l;++i){b[i]=a[i]}return b}function map(f,a){var l=a.length;var b=new Array(l);for(var i=0;i<l;++i){b[i]=f(a[i])}return b}function reduce(f,z,a){var r=z;for(var i=0,l=a.length;i<l;++i){r=f(r,a[i],i)}return r}function replace(x,i,a){if(i<0){throw new TypeError("i must be >= 0")}var l=a.length;var b=new Array(l);for(var j=0;j<l;++j){b[j]=i===j?x:a[j]}return b}function remove(i,a){if(i<0){throw new TypeError("i must be >= 0")}var l=a.length;if(l===0||i>=l){return a}if(l===1){return[]}return unsafeRemove(i,a,l-1)}function unsafeRemove(i,a,l){var b=new Array(l);var j;for(j=0;j<i;++j){b[j]=a[j]}for(j=i;j<l;++j){b[j]=a[j+1]}return b}function removeAll(f,a){var l=a.length;var b=new Array(l);var j=0;for(var x,i=0;i<l;++i){x=a[i];if(!f(x)){b[j]=x;++j}}b.length=j;return b}function findIndex(x,a){for(var i=0,l=a.length;i<l;++i){if(x===a[i]){return i}}return-1}function isArrayLike(x){return x!=null&&typeof x.length==="number"&&typeof x!=="function"}var id=function(x){return x};var compose=function(f,g){return function(x){return f(g(x))}};var apply=function(f,x){return f(x)};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)}}return curried}function curry3(f){function curried(a,b,c){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)}}return curried}function curry4(f){function curried(a,b,c,d){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)}}return curried}exports.cons=cons;exports.append=append;exports.drop=drop;exports.tail=tail;exports.copy=copy;exports.map=map;exports.reduce=reduce;exports.replace=replace;exports.remove=remove;exports.removeAll=removeAll;exports.findIndex=findIndex;exports.isArrayLike=isArrayLike;exports.id=id;exports.compose=compose;exports.apply=apply;exports.curry2=curry2;exports.curry3=curry3;exports.curry4=curry4;Object.defineProperty(exports,"__esModule",{value:true})}); |
{ | ||
"name": "@most/prelude", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "prelude", | ||
@@ -5,0 +5,0 @@ "main": "dist/prelude.js", |
@@ -36,1 +36,15 @@ /** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
} | ||
// curry4 :: ((a, b, c, d) -> e) -> (a -> b -> c -> d -> e) | ||
export function curry4 (f) { | ||
function curried (a, b, c, d) { // eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry3((b, c, d) => f(a, b, c, d)) | ||
case 2: return curry2((c, d) => f(a, b, c, d)) | ||
case 3: return d => f(a, b, c, d) | ||
default:return f(a, b, c, d) | ||
} | ||
} | ||
return curried | ||
} |
@@ -47,4 +47,14 @@ // array.js | ||
interface CurriedFunction4<A, B, C, D, E> { | ||
(): CurriedFunction4<A, B, C, D, E>; | ||
(a: A): CurriedFunction3<B, C, D, E>; | ||
(a: A, b: B): CurriedFunction2<C, D, E>; | ||
(a: A, b: B, c: C): (d: D) => E; | ||
(a: A, b: B, c: C, d: D): E; | ||
} | ||
export function curry2<A, B, C>(f: (a: A, b: B) => C): CurriedFunction2<A, B, C>; | ||
export function curry3<A, B, C, D>(f: (a: A, b: B, c: C) => D): CurriedFunction3<A, B, C, D>; | ||
export function curry4<A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E): CurriedFunction4<A, B, C, D, E>; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
29523
461