rubico
Version:
[a]synchronous functional programming
9 lines (8 loc) • 1.19 kB
JavaScript
/**
* Rubico v2.8.2
* https://rubico.land/
*
* © Richard Yufei Tong, King of Software
* Rubico may be freely distributed under the CFOSS 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),__=Symbol.for("placeholder"),curry3ResolveArg0=(r,n,e)=>function(t){return r(t,n,e)},curry3ResolveArg1=(r,n,e)=>function(t){return r(n,t,e)},curry3ResolveArg2=(r,n,e)=>function(t){return r(n,e,t)},curry3=function(r,n,e,t){return n==__?curry3ResolveArg0(r,e,t):e==__?curry3ResolveArg1(r,n,t):curry3ResolveArg2(r,n,e)},funcApply2=(r,n,e)=>r.apply(n,e);function _thunkifyArgs(r,n,e){return function(){return r.apply(n,e)}}const thunkify=function(r,...n){return areAnyValuesPromises(n)?promiseAll(n).then(curry3(_thunkifyArgs,r,this,__)):_thunkifyArgs(r,this,n)};thunkify.call=function(r,n,...e){return areAnyValuesPromises(e)?promiseAll(e).then(curry3(_thunkifyArgs,r,n,__)):_thunkifyArgs(r,n,e)};export default thunkify;