UNPKG

rubico

Version:

[a]synchronous functional programming

9 lines (7 loc) 1.85 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.or=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=Promise.all.bind(Promise),t=n=>null!=n&&"function"==typeof n.then,r=Array.isArray,e=Symbol.for("placeholder"),o=function(n,t,r,o){return t==e?((n,t,r)=>function(e){return n(e,t,r)})(n,r,o):r==e?((n,t,r)=>function(e){return n(t,e,r)})(n,t,o):((n,t,r)=>function(e){return n(t,r,e)})(n,t,r)},u=(n,t,r)=>n?t():r(),f=(n,t,r)=>function(){return n(t,r)},i=(n,t,r,e)=>function(){return n(t,r,e)},c=n=>function(){return n},l=function(n,r){const i=n.length;for(;++r<i;){const i=n[r];if(t(i))return i.then(o(u,e,c(!0),f(l,n,r)));if(i)return!0}return!1},s=async function(n,r,e){const o=r.length;for(;++e<o;){let o=r[e];if("function"==typeof o&&(o=o(...n)),t(o)&&(o=await o),o)return!0}return!1},h=function(n,r){const f=r.length;let l=-1;for(;++l<f;){let f=r[l];if("function"==typeof f&&(f=f(...n)),t(f))return f.then(o(u,e,c(!0),i(s,n,r,l)));if(f)return!0}return!1};return function(...o){const u=o.pop();return function(n){if(r(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}(u)?l(u,-1):0==o.length?(f=h,c=u,(i=e)==e?((n,t)=>function(...r){return n(r,t)})(f,c):((n,t)=>function(...r){return n(t,r)})(f,i)):function(n){if(r(n)){const r=n.length;let e=-1;for(;++e<r;){const r=n[e];if(t(r))return!0}return!1}for(const r in n){const e=n[r];if(t(e))return!0}return!1}(o)?n(o).then(function(n,t,r){return t==e?((n,t)=>function(r){return n(r,t)})(n,r):((n,t)=>function(r){return n(t,r)})(n,t)}(h,e,u)):h(o,u);var f,i,c}}());