@thi.ng/compose
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -6,2 +6,10 @@ # Change Log | ||
## [1.3.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/compose@1.3.1...@thi.ng/compose@1.3.2) (2019-07-31) | ||
**Note:** Version bump only for package @thi.ng/compose | ||
## [1.3.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/compose@1.3.0...@thi.ng/compose@1.3.1) (2019-07-12) | ||
@@ -8,0 +16,0 @@ |
@@ -1,160 +0,1 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@thi.ng/errors')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@thi.ng/errors'], factory) : | ||
(global = global || self, factory((global.thi = global.thi || {}, global.thi.ng = global.thi.ng || {}, global.thi.ng.compose = {}), global.thi.ng.errors)); | ||
}(this, function (exports, errors) { 'use strict'; | ||
function comp(...fns) { | ||
let [a, b, c, d, e, f, g, h, i, j] = fns; | ||
switch (fns.length) { | ||
case 0: | ||
errors.illegalArity(0); | ||
case 1: | ||
return a; | ||
case 2: | ||
return (...xs) => a(b(...xs)); | ||
case 3: | ||
return (...xs) => a(b(c(...xs))); | ||
case 4: | ||
return (...xs) => a(b(c(d(...xs)))); | ||
case 5: | ||
return (...xs) => a(b(c(d(e(...xs))))); | ||
case 6: | ||
return (...xs) => a(b(c(d(e(f(...xs)))))); | ||
case 7: | ||
return (...xs) => a(b(c(d(e(f(g(...xs))))))); | ||
case 8: | ||
return (...xs) => a(b(c(d(e(f(g(h(...xs)))))))); | ||
case 9: | ||
return (...xs) => a(b(c(d(e(f(g(h(i(...xs))))))))); | ||
case 10: | ||
default: | ||
const fn = (...xs) => a(b(c(d(e(f(g(h(i(j(...xs)))))))))); | ||
return fns.length === 10 ? fn : comp(fn, ...fns.slice(10)); | ||
} | ||
} | ||
function compL(...fns) { | ||
return comp.apply(null, fns.reverse()); | ||
} | ||
const compI = compL; | ||
function complement(f) { | ||
return (...xs) => !f(...xs); | ||
} | ||
const constantly = (x) => () => x; | ||
const delay = (body) => new Delay(body); | ||
class Delay { | ||
constructor(body) { | ||
this.body = body; | ||
this.realized = false; | ||
} | ||
deref() { | ||
if (!this.realized) { | ||
this.value = this.body(); | ||
this.realized = true; | ||
} | ||
return this.value; | ||
} | ||
isRealized() { | ||
return this.realized; | ||
} | ||
} | ||
const delayed = (x, t) => new Promise((resolve) => setTimeout(() => resolve(x), t)); | ||
const identity = (x) => x; | ||
const ifDef = (f, x) => x != null ? f(x) : undefined; | ||
function juxt(...fns) { | ||
const [a, b, c, d, e, f, g, h] = fns; | ||
switch (fns.length) { | ||
case 1: | ||
return (x) => [a(x)]; | ||
case 2: | ||
return (x) => [a(x), b(x)]; | ||
case 3: | ||
return (x) => [a(x), b(x), c(x)]; | ||
case 4: | ||
return (x) => [a(x), b(x), c(x), d(x)]; | ||
case 5: | ||
return (x) => [a(x), b(x), c(x), d(x), e(x)]; | ||
case 6: | ||
return (x) => [a(x), b(x), c(x), d(x), e(x), f(x)]; | ||
case 7: | ||
return (x) => [a(x), b(x), c(x), d(x), e(x), f(x), g(x)]; | ||
case 8: | ||
return (x) => [a(x), b(x), c(x), d(x), e(x), f(x), g(x), h(x)]; | ||
default: | ||
return (x) => { | ||
let res = new Array(fns.length); | ||
for (let i = fns.length; --i >= 0;) { | ||
res[i] = fns[i](x); | ||
} | ||
return res; | ||
}; | ||
} | ||
} | ||
function partial(fn, ...args) { | ||
let [a, b, c, d, e, f, g, h] = args; | ||
switch (args.length) { | ||
case 1: | ||
return (...xs) => fn(a, ...xs); | ||
case 2: | ||
return (...xs) => fn(a, b, ...xs); | ||
case 3: | ||
return (...xs) => fn(a, b, c, ...xs); | ||
case 4: | ||
return (...xs) => fn(a, b, c, d, ...xs); | ||
case 5: | ||
return (...xs) => fn(a, b, c, d, e, ...xs); | ||
case 6: | ||
return (...xs) => fn(a, b, c, d, e, f, ...xs); | ||
case 7: | ||
return (...xs) => fn(a, b, c, d, e, f, g, ...xs); | ||
case 8: | ||
return (...xs) => fn(a, b, c, d, e, f, g, h, ...xs); | ||
default: | ||
errors.illegalArgs(); | ||
} | ||
} | ||
const foo = partial((a, b) => a + b, "a"); | ||
const threadFirst = (init, ...fns) => fns.reduce((acc, expr) => typeof expr === "function" | ||
? expr(acc) | ||
: expr[0](acc, ...expr.slice(1)), init); | ||
const threadLast = (init, ...fns) => fns.reduce((acc, expr) => typeof expr === "function" | ||
? expr(acc) | ||
: expr[0](...expr.slice(1), acc), init); | ||
const trampoline = (f) => { | ||
while (typeof f === "function") { | ||
f = f(); | ||
} | ||
return f; | ||
}; | ||
exports.Delay = Delay; | ||
exports.comp = comp; | ||
exports.compI = compI; | ||
exports.compL = compL; | ||
exports.complement = complement; | ||
exports.constantly = constantly; | ||
exports.delay = delay; | ||
exports.delayed = delayed; | ||
exports.foo = foo; | ||
exports.identity = identity; | ||
exports.ifDef = ifDef; | ||
exports.juxt = juxt; | ||
exports.partial = partial; | ||
exports.threadFirst = threadFirst; | ||
exports.threadLast = threadLast; | ||
exports.trampoline = trampoline; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/errors"],t):t(((e=e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.compose={}),e.thi.ng.errors)}(this,function(e,t){"use strict";function r(...e){let[n,s,c,u,i,a,o,l,f,d]=e;switch(e.length){case 0:t.illegalArity(0);case 1:return n;case 2:return(...e)=>n(s(...e));case 3:return(...e)=>n(s(c(...e)));case 4:return(...e)=>n(s(c(u(...e))));case 5:return(...e)=>n(s(c(u(i(...e)))));case 6:return(...e)=>n(s(c(u(i(a(...e))))));case 7:return(...e)=>n(s(c(u(i(a(o(...e)))))));case 8:return(...e)=>n(s(c(u(i(a(o(l(...e))))))));case 9:return(...e)=>n(s(c(u(i(a(o(l(f(...e)))))))));case 10:default:const h=(...e)=>n(s(c(u(i(a(o(l(f(d(...e))))))))));return 10===e.length?h:r(h,...e.slice(10))}}function n(...e){return r.apply(null,e.reverse())}const s=n;class c{constructor(e){this.body=e,this.realized=!1}deref(){return this.realized||(this.value=this.body(),this.realized=!0),this.value}isRealized(){return this.realized}}function u(e,...r){let[n,s,c,u,i,a,o,l]=r;switch(r.length){case 1:return(...t)=>e(n,...t);case 2:return(...t)=>e(n,s,...t);case 3:return(...t)=>e(n,s,c,...t);case 4:return(...t)=>e(n,s,c,u,...t);case 5:return(...t)=>e(n,s,c,u,i,...t);case 6:return(...t)=>e(n,s,c,u,i,a,...t);case 7:return(...t)=>e(n,s,c,u,i,a,o,...t);case 8:return(...t)=>e(n,s,c,u,i,a,o,l,...t);default:t.illegalArgs()}}const i=u((e,t)=>e+t,"a");e.Delay=c,e.comp=r,e.compI=s,e.compL=n,e.complement=function(e){return(...t)=>!e(...t)},e.constantly=e=>()=>e,e.delay=e=>new c(e),e.delayed=(e,t)=>new Promise(r=>setTimeout(()=>r(e),t)),e.foo=i,e.identity=e=>e,e.ifDef=(e,t)=>null!=t?e(t):void 0,e.juxt=function(...e){const[t,r,n,s,c,u,i,a]=e;switch(e.length){case 1:return e=>[t(e)];case 2:return e=>[t(e),r(e)];case 3:return e=>[t(e),r(e),n(e)];case 4:return e=>[t(e),r(e),n(e),s(e)];case 5:return e=>[t(e),r(e),n(e),s(e),c(e)];case 6:return e=>[t(e),r(e),n(e),s(e),c(e),u(e)];case 7:return e=>[t(e),r(e),n(e),s(e),c(e),u(e),i(e)];case 8:return e=>[t(e),r(e),n(e),s(e),c(e),u(e),i(e),a(e)];default:return t=>{let r=new Array(e.length);for(let n=e.length;--n>=0;)r[n]=e[n](t);return r}}},e.partial=u,e.threadFirst=(e,...t)=>t.reduce((e,t)=>"function"==typeof t?t(e):t[0](e,...t.slice(1)),e),e.threadLast=(e,...t)=>t.reduce((e,t)=>"function"==typeof t?t(e):t[0](...t.slice(1),e),e),e.trampoline=e=>{for(;"function"==typeof e;)e=e();return e},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@thi.ng/compose", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Arity-optimized functional composition helpers", | ||
@@ -17,22 +17,23 @@ "module": "./index.js", | ||
"scripts": { | ||
"build": "yarn clean && yarn build:es6 && yarn build:bundle", | ||
"build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module", | ||
"build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all", | ||
"build:es6": "tsc --declaration", | ||
"build:bundle": "../../scripts/bundle-module", | ||
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js", | ||
"build:test": "rimraf build && tsc -p test/tsconfig.json", | ||
"test": "yarn build:test && mocha build/test/*.js", | ||
"cover": "yarn build:test && nyc mocha build/test/*.js && nyc report --reporter=lcov", | ||
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib", | ||
"cover": "yarn test && nyc report --reporter=lcov", | ||
"doc": "node_modules/.bin/typedoc --mode modules --out doc --ignoreCompilerErrors src", | ||
"pub": "yarn build && yarn publish --access public" | ||
"pub": "yarn build:release && yarn publish --access public" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^12.0.8", | ||
"@types/node": "^12.6.3", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.0.0", | ||
"typedoc": "^0.14.2", | ||
"typescript": "^3.5.2" | ||
"typescript": "^3.5.3" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/api": "^6.3.1", | ||
"@thi.ng/errors": "^1.1.1" | ||
"@thi.ng/api": "^6.3.2", | ||
"@thi.ng/errors": "^1.1.2" | ||
}, | ||
@@ -49,3 +50,3 @@ "keywords": [ | ||
"sideEffects": false, | ||
"gitHead": "47075afc37f3a16adee7c903a2935304c7cf5daf" | ||
"gitHead": "53eec7988c378fc37ae140e7174f36ef9b6208fe" | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
56565
551
1
Updated@thi.ng/api@^6.3.2
Updated@thi.ng/errors@^1.1.2