UNPKG

rubico

Version:

[a]synchronous functional programming

8 lines (7 loc) 980 B
/** * rubico v2.6.2 * https://github.com/a-synchronous/rubico * (c) 2019-2024 Richard Tong * rubico may be freely distributed under the MIT license. */ const __=Symbol.for("placeholder"),curry2ResolveArg0=(r,e)=>function(n){return r(n,e)},curry2ResolveArg1=(r,e)=>function(n){return r(e,n)},curry2=function(r,e,n){return e==__?curry2ResolveArg0(r,n):curry2ResolveArg1(r,e)},promiseAll=Promise.all.bind(Promise),funcApply=(r,e)=>r(...e),isArray=Array.isArray,isPromise=r=>null!=r&&"function"==typeof r.then,areAnyValuesPromises=function(r){if(isArray(r)){const e=r.length;let n=-1;for(;++n<e;){const e=r[n];if(isPromise(e))return!0}return!1}for(const e in r){const n=r[e];if(isPromise(n))return!0}return!1},funcConcat=(r,e)=>function(...n){const o=r(...n);return isPromise(o)?o.then(e):e(o)},compose=function(...r){const e=r.pop().reduceRight(funcConcat);return 0==r.length?e:areAnyValuesPromises(r)?promiseAll(r).then(curry2(funcApply,e,__)):e(...r)};export default compose;