rubico
Version:
[a]synchronous functional programming
9 lines (8 loc) • 1.04 kB
JavaScript
/**
* Rubico v2.8.3
* https://rubico.land/
*
* © Richard Yufei Tong, King of Software
* Rubico may be freely distributed under the CFOSS license.
*/
const __=Symbol.for("placeholder"),curry2ResolveArg0=(r,n)=>function(e){return r(e,n)},curry2ResolveArg1=(r,n)=>function(e){return r(n,e)},curry2=function(r,n,e){return n==__?curry2ResolveArg0(r,e):curry2ResolveArg1(r,n)},promiseAll=Promise.all.bind(Promise),funcApply=(r,n)=>r(...n),isArray=Array.isArray,isPromise=r=>null!=r&&"function"==typeof r.then,areAnyValuesPromises=function(r){if(isArray(r)){const n=r.length;let e=-1;for(;++e<n;){const n=r[e];if(isPromise(n))return!0}return!1}for(const n in r){const e=r[n];if(isPromise(e))return!0}return!1},funcConcat=(r,n)=>function(...e){const o=r(...e);return isPromise(o)?o.then(n):n(o)},compose=function(...r){if("function"==typeof r[0])return r.reduceRight(funcConcat);const n=r.pop().reduceRight(funcConcat);return 0==r.length?n:areAnyValuesPromises(r)?promiseAll(r).then(curry2(funcApply,n,__)):n(...r)};export default compose;