UNPKG

rubico

Version:

[a]synchronous functional programming

10 lines (8 loc) 1.94 kB
/** * Rubico v2.8.2 * https://rubico.land/ * * © Richard Yufei Tong, King of Software * Rubico may be freely distributed under the CFOSS license. */ !function(n,t){"object"==typeof module?module.exports=t:"function"==typeof define?define(()=>t):n.curry=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=Array.isArray,t=n=>null!=n&&"function"==typeof n.then,e=function(e){if(n(e)){const n=e.length;let r=-1;for(;++r<n;){const n=e[r];if(t(n))return!0}return!1}for(const n in e){const r=e[n];if(t(r))return!0}return!1},r=Promise.all.bind(Promise),o=Symbol.for("placeholder"),u=function(n,t,e,r,u){return t==o?((n,t,e,r)=>function(o){return n(o,t,e,r)})(n,e,r,u):e==o?((n,t,e,r)=>function(o){return n(t,o,e,r)})(n,t,r,u):r==o?((n,t,e,r)=>function(o){return n(t,e,o,r)})(n,t,e,u):((n,t,e,r)=>function(o){return n(t,e,r,o)})(n,t,e,r)},i=function(n,t,e,r){return t==o?((n,t,e)=>function(r){return n(r,t,e)})(n,e,r):e==o?((n,t,e)=>function(r){return n(t,r,e)})(n,t,r):((n,t,e)=>function(r){return n(t,e,r)})(n,t,e)},f=(n,t,e)=>n.apply(t,e),c=(n,t,c,h)=>function(...s){const p=h.length,y=s.length,a=[];let g=-1,b=-1,d=0;for(;++g<p;){const p=h[g];if(p==o&&(b+=1)<y){const n=s[b];n==o&&(d+=1),a.push(n)}else a.push(p);if(a.length==n)return e(a)?0==d?r(a).then(i(f,t,c,o)):r(a).then(u(l,n,t,c,o)):0==d?t.apply(c,a):l(n,t,c,a)}for(;++b<y;){const h=s[b];if(h==o&&(d+=1),a.push(h),a.length==n)return e(a)?0==d?r(a).then(i(f,t,c,o)):r(a).then(u(l,n,t,c,o)):0==d?t.apply(c,a):l(n,t,c,a)}return e(a)?r(a).then(u(l,n,t,c,o)):l(n,t,c,a)},l=function(n,t,e,r){const u=r.length;if(u<n)return c(n,t,e,r);let i=-1;for(;++i<u;){if(r[i]==o)return c(n,t,e,r)}return t.apply(e,r)},h=(n,...t)=>e(t)?r(t).then(u(l,n.length,n,this,o)):l(n.length,n,this,t);return h.arity=function(n,t,...i){return e(i)?r(i).then(u(l,n,t,this,o)):l(n,t,this,i)},h.call=function(n,t,...i){return e(i)?r(i).then(u(l,n.length,n,t,o)):l(n.length,n,t,i)},h}());