rubico
Version:
[a]synchronous functional programming
8 lines (7 loc) • 1.02 kB
JavaScript
/**
* rubico v2.7.7
* https://github.com/a-synchronous/rubico
* (c) 2019-2025 Richard Tong
* rubico may be freely distributed under the MIT license.
*/
const 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},promiseAll=Promise.all.bind(Promise),funcConcat=(r,n)=>function(...e){const o=r(...e);return isPromise(o)?o.then(n):n(o)},funcApply=(r,n)=>r(...n),__=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)},pipe=function(...r){if("function"==typeof r[0])return r.reduce(funcConcat);const n=r.pop().reduce(funcConcat);return 0==r.length?n:areAnyValuesPromises(r)?promiseAll(r).then(curry2(funcApply,n,__)):n(...r)};export default pipe;