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