rubico
Version:
[a]synchronous functional programming
9 lines (7 loc) • 1.76 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.differenceWith=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=Symbol.for("placeholder"),t=function(t,r,e){return r==n?((n,t)=>function(r){return n(r,t)})(t,e):((n,t)=>function(r){return n(t,r)})(t,r)},r=(n,t,r)=>function(){return n(t,r)},e=(n,t,r,e,o,u)=>function(){return n(t,r,e,o,u)},o=(n,t,r)=>n?t():r(),u=n=>null!=n&&"function"==typeof n.then,i=Array.isArray,f=function(n){const t=n.then((n=>[n,t]));return t},c=Promise.race.bind(Promise),s=async function(n,t,r,e){const o=n.length;for(;++r<o;){const o=t(n[r]);if(u(o))e.add(f(o));else if(o)return!0}for(;e.size>0;){const[n,t]=await c(e);if(e.delete(t),n)return!0}return!1},l=function(n,t){const r=n.length;let e=-1;for(;++e<r;){const r=t(n[e]);if(u(r))return s(n,t,e,new Set([f(r)]));if(r)return!0}return!1},a=function(n,t){return n.push(t),n},h=(n,t)=>function(...r){return t(n(...r))},y=function(){},d=(Symbol.iterator,Symbol.asyncIterator,async function(r,e,o,i,f){const c=e.length;for(;++f<c;){const c=e[f];let s=l(o,t(r,c,n));u(s)&&(s=await s),s||i.push(c)}return i});return(f,c)=>function(s){if(i(s))return function(i,f,c){const s=f.length,p=[];let b=-1;for(;++b<s;){const s=f[b],A=l(c,t(i,s,n));if(u(A))return A.then(h((m=o,g=n,w=y,S=r(a,p,s),g==n?((n,t,r)=>function(e){return n(e,t,r)})(m,w,S):w==n?((n,t,r)=>function(e){return n(t,e,r)})(m,g,S):((n,t,r)=>function(e){return n(t,r,e)})(m,g,w)),e(d,i,f,c,p,b)));A||p.push(s)}var m,g,w,S;return p}(f,c,s);throw new TypeError(`${s} is not an Array`)}}());