UNPKG

rubico

Version:

[a]synchronous functional programming

9 lines (7 loc) 3.43 kB
/** * rubico v2.7.7 * https://github.com/a-synchronous/rubico * (c) 2019-2025 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.filterOut=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=Symbol.for("placeholder"),t=function(t,e,r){return e==n?((n,t)=>function(e){return n(e,t)})(t,r):((n,t)=>function(e){return n(t,e)})(t,e)},e=Symbol.iterator,r=(n,t)=>({[e](){return this},next(){let e=n.next();for(;!e.done;){const{value:r}=e;if(t(r))return{value:r,done:!1};e=n.next()}return e}}),o=n=>null!=n&&"function"==typeof n.then,u=Symbol.asyncIterator,c=(n,t)=>({isAsyncIteratorDone:!1,[u](){return this},async next(){for(;!this.isAsyncIteratorDone;){const{value:e,done:r}=await n.next();if(r)this.isAsyncIteratorDone=!0;else{const n=t(e);if(o(n)?await n:n)return{value:e,done:!1}}}return{value:void 0,done:!0}}}),i=Array.isArray,f=function(t,e,r,o,u){return e==n?((n,t,e,r)=>function(o){return n(o,t,e,r)})(t,r,o,u):r==n?((n,t,e,r)=>function(o){return n(t,o,e,r)})(t,e,o,u):o==n?((n,t,e,r)=>function(o){return n(t,e,o,r)})(t,e,r,u):((n,t,e,r)=>function(o){return n(t,e,r,o)})(t,e,r,o)},s=Promise.all.bind(Promise),l=function(n,t,e,r){const o=t.length;let u=n.length-1;for(;++r<o;)n[++u]=e(t[r],r,n);return n},h=function(n,t,e,r){const o=n.length;let u=-1;for(;++e<o;)r[++u]&&t.push(n[e]);return t},a=function(t,e){const r=t.length,u=[];let c=-1,i=-1;for(;++c<r;){const r=t[c],a=e(r,c,t);if(o(a))return s(l([a],t,e,c)).then(f(h,t,u,c-1,n));a&&(u[++i]=r)}return u},p=function(t,e,r,o){return e==n?((n,t,e)=>function(r){return n(r,t,e)})(t,r,o):r==n?((n,t,e)=>function(r){return n(t,r,e)})(t,e,o):((n,t,e)=>function(r){return n(t,e,r)})(t,e,r)},y=(n,t,e)=>n[t](e),d=n=>function(){return n},g=(n,t,e)=>n?t():e(),b=(n,t)=>function(){return n(t)},v=function(){},m=(n,t,e,r,o)=>function(){return n(t,e,r,o)},x=(n,t,e,r)=>n[t](e,r),S=function(n,t,e,r){r&&(n[t]=e)},j=function(t,l){return i(t)?a(t,l):null==t?t:"string"==typeof t||t.constructor==String?function(t,e){const r=a(t,e);return o(r)?r.then(p(y,n,"join","")):r.join("")}(t,l):t.constructor==Set?function(t,e){const r=new Set,u=r.add.bind(r),c=[];for(const i of t){const f=e(i,i,t);o(f)?c.push(f.then(p(g,n,b(u,i),v))):f&&r.add(i)}return 0==c.length?r:s(c).then(d(r))}(t,l):t.constructor==Map?function(t,e){const r=new Map,u=[];for(const[c,i]of t){const f=e(i,c,t);o(f)?u.push(f.then(p(g,n,m(x,r,"set",c,i),v))):f&&r.set(c,i)}return 0==u.length?r:s(u).then(d(r))}(t,l):"function"==typeof t.filter?t.filter(l):"function"==typeof t[e]?r(t[e](),l):"function"==typeof t[u]?c(t[u](),l):t.constructor==Object?function(t,e){const r={},u=[];for(const c in t){const i=t[c],s=e(i,c,t);o(s)?u.push(s.then(f(S,r,c,t[c],n))):s&&(r[c]=i)}return 0==u.length?r:s(u).then(d(r))}(t,l):t},A=n=>!n,w=function(n,t){const e=t(...n);return o(e)?e.then(A):!e},I=function(...e){const r=e.pop();return"function"==typeof r?0==e.length?(u=w,f=r,(c=n)==n?((n,t)=>function(...e){return n(e,t)})(u,f):((n,t)=>function(...e){return n(t,e)})(u,c)):function(n){if(i(n)){const t=n.length;let e=-1;for(;++e<t;){const t=n[e];if(o(t))return!0}return!1}for(const t in n){const e=n[t];if(o(e))return!0}return!1}(e)?s(e).then(t(w,n,r)):w(e,r):o(r)?r.then(A):!r;var u,c,f};return e=>{return"function"==typeof(r=I(e))?t(j,n,r):o(r)?r.then(t(j,n,u)):j(r,u);var r,u}}());