UNPKG

rubico

Version:

[a]synchronous functional programming

9 lines (7 loc) 1.87 kB
/** * rubico v2.6.2 * https://github.com/a-synchronous/rubico * (c) 2019-2024 Richard Tong * rubico may be freely distributed under the MIT license. */ !function(n,t){"object"==typeof module?module.exports=t:"function"==typeof define?define((()=>t)):n.switchCase=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=Promise.all.bind(Promise),t=Array.isArray,r=n=>null!=n&&"function"==typeof n.then,o=(n,t,r)=>n?t():r(),e=(n,t)=>function(){return n(...t)},u=(n,t,r,o)=>function(){return n(t,r,o)},f=Symbol.for("placeholder"),i=function(n,t,r,o){return t==f?((n,t,r)=>function(o){return n(o,t,r)})(n,r,o):r==f?((n,t,r)=>function(o){return n(t,o,r)})(n,t,o):((n,t,r)=>function(o){return n(t,r,o)})(n,t,r)},c=n=>function(){return n},s=function(n,t,l){const h=n.length-1;for(;(l+=2)<h;){const h=n[l],p=n[l+1],y="function"==typeof h?h(...t):h;if(r(y))return y.then(i(o,f,"function"==typeof p?e(p,t):c(p),u(s,n,t,l)));if(y)return"function"==typeof p?p(...t):p}if(l==n.length)return;const p=n[h];return"function"==typeof p?p(...t):p},l=(n,t,r)=>function(){return n(t,r)},h=function(n,t){const e=n.length,u=e-1;for(;(t+=2)<u;){const e=n[t],u=n[t+1];if(r(e))return e.then(i(o,f,c(u),l(h,n,t)));if(e)return u}if(t!=e)return n[t]};return(...o)=>{const e=o.pop();return function(n){if(t(n)){const t=n.length;let r=-1;for(;++r<t;)if("function"==typeof n[r])return!1;return!0}for(const t in n)if("function"==typeof n[t])return!1;return!0}(e)?h(e,-2):0==o.length?(u=s,l=f,p=-2,(c=e)==f?((n,t,r)=>function(...o){return n(o,t,r)})(u,l,p):l==f?((n,t,r)=>function(...o){return n(t,o,r)})(u,c,p):((n,t,r)=>function(...o){return n(t,r,o)})(u,c,l)):function(n){if(t(n)){const t=n.length;let o=-1;for(;++o<t;){const t=n[o];if(r(t))return!0}return!1}for(const t in n){const o=n[t];if(r(o))return!0}return!1}(o)?n(o).then(i(s,e,f,-2)):s(e,o,-2);var u,c,l,p}}());