UNPKG

rubico

Version:

[a]synchronous functional programming

10 lines (8 loc) 3.28 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.reduce=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=n=>null!=n&&"function"==typeof n.then,t=Symbol.for("placeholder"),e=function(n,e,r,o){return e==t?((n,t,e)=>function(r){return n(r,t,e)})(n,r,o):r==t?((n,t,e)=>function(r){return n(t,r,e)})(n,e,o):((n,t,e)=>function(r){return n(t,e,r)})(n,e,r)},r=Array.isArray,o=(Object.values,Object.prototype.toString,async function(t,e,r){let o=t.next();if(o.done)return r;for(;!o.done;)r=e(r,o.value),n(r)&&(r=await r),o=t.next();return r}),u=Symbol.iterator,f=Symbol.asyncIterator,i=function(n,e,r){return e==t?((n,t)=>function(e){return n(e,t)})(n,r):((n,t)=>function(e){return n(t,e)})(n,e)},c=function(n,e,r,o,u){return e==t?((n,t,e,r)=>function(o){return n(o,t,e,r)})(n,r,o,u):r==t?((n,t,e,r)=>function(o){return n(t,o,e,r)})(n,e,o,u):o==t?((n,t,e,r)=>function(o){return n(t,e,o,r)})(n,e,r,u):((n,t,e,r)=>function(o){return n(t,e,r,o)})(n,e,r,o)},a=async function(t,e,r,o){const u=t.length;for(;++o<u;)r=e(r,t[o],o,t),n(r)&&(r=await r);return r},l=function(n,e,r,o,u,f){return e==t?((n,t,e,r,o)=>function(u){return n(u,t,e,r,o)})(n,r,o,u,f):r==t?((n,t,e,r,o)=>function(u){return n(t,u,e,r,o)})(n,e,o,u,f):o==t?((n,t,e,r,o)=>function(u){return n(t,e,u,r,o)})(n,e,r,u,f):u==t?((n,t,e,r,o)=>function(u){return n(t,e,r,u,o)})(n,e,r,o,f):((n,t,e,r,o)=>function(u){return n(t,e,r,o,u)})(n,e,r,o,u)},s=Object.keys,y=async function(t,e,r,o,u){const f=o.length;for(;++u<f;){const f=o[u];r=e(r,t[f],f,t),n(r)&&(r=await r)}return r},d=async function(t,e,r,o){for(const[u,f]of o)r=e(r,f,u,t),n(r)&&(r=await r);return r},h=function(h,p,v){return r(h)?function(e,r,o){const u=e.length;let f=-1;for(void 0===o&&(o=e[++f]);++f<u;)if(o=r(o,e[f],f,e),n(o))return o.then(c(a,e,r,t,f));return o}(h,p,v):null==h?void 0===v?i(p,h,t):p(v,h):h.constructor==Map?function(e,r,o){const u=e.entries();if(void 0===o){const n=u.next();if(n.done)return o;o=n.value[1]}for(const[f,i]of u)if(o=r(o,i,f,e),n(o))return o.then(c(d,e,r,t,u));return o}(h,p,v):"function"==typeof h[u]?function(r,u,f){let i=r.next();if(i.done)return f;for(void 0===f&&(f=i.value,i=r.next());!i.done;){if(f=u(f,i.value),n(f))return f.then(e(o,r,u,t));i=r.next()}return f}(h[u](),p,v):"function"==typeof h[f]?async function(n,t,e){let r=await n.next();if(r.done)return e;for(void 0===e&&(e=r.value,r=await n.next());!r.done;)e=await t(e,r.value),r=await n.next();return e}(h[f](),p,v):"function"==typeof h.reduce?h.reduce(p,v):"function"==typeof h.chain?h.chain(i(p,v,t)):"function"==typeof h.flatMap?h.flatMap(i(p,v,t)):h.constructor==Object?function(e,r,o){const u=s(e),f=u.length;let i=-1;for(void 0===o&&(o=e[u[++i]]);++i<f;){const f=u[i];if(o=r(o,e[f],f,e),n(o))return o.then(l(y,e,r,t,u,i))}return o}(h,p,v):void 0===v?i(p,h,t):p(v,h)},p=function(r,o,u){if("function"==typeof u){const f=u(r);return n(f)?f.then(e(h,r,o,t)):h(r,o,f)}return n(u)?u.then(e(h,r,o,t)):h(r,o,u)};return function(...r){return"function"==typeof r[0]?e(p,t,r[0],r[1]):n(r[0])?r[0].then(e(p,t,r[1],r[2])):p(r[0],r[1],r[2])}}());