rubico
Version:
[a]synchronous functional programming
9 lines (7 loc) • 1.1 kB
JavaScript
/**
* 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.tryCatch=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=n=>null!=n&&"function"==typeof n.then,t=Promise.all.bind(Promise),r=Symbol.for("placeholder"),o=function(n,t,o,e){return t==r?((n,t,r)=>function(o){return n(o,t,r)})(n,o,e):o==r?((n,t,r)=>function(o){return n(t,o,r)})(n,t,e):((n,t,r)=>function(o){return n(t,r,o)})(n,t,o)},e=function(n,t,r){return n(t,...r)},u=Array.isArray,c=function(t,u,c){try{const i=t(...c);return n(i)?i.catch(o(e,u,r,c)):i}catch(n){return u(n,...c)}};return function(...e){if(e.length>2){const i=e.pop(),f=e.pop();return function(t){if(u(t)){const r=t.length;let o=-1;for(;++o<r;){const r=t[o];if(n(r))return!0}return!1}for(const r in t){const o=t[r];if(n(o))return!0}return!1}(e)?t(e).then(o(c,f,i,r)):c(f,i,e)}const i=e[0],f=e[1];return function(...n){return c(i,f,n)}}}());