UNPKG

rubico

Version:

[a]synchronous functional programming

8 lines (7 loc) 2.23 kB
/** * rubico v2.6.2 * https://github.com/a-synchronous/rubico * (c) 2019-2024 Richard Tong * rubico may be freely distributed under the MIT license. */ const __=Symbol.for("placeholder"),curry2ResolveArg0=(r,n)=>function(e){return r(e,n)},curry2ResolveArg1=(r,n)=>function(e){return r(n,e)},curry2=function(r,n,e){return n==__?curry2ResolveArg0(r,e):curry2ResolveArg1(r,n)},curry3ResolveArg0=(r,n,e)=>function(t){return r(t,n,e)},curry3ResolveArg1=(r,n,e)=>function(t){return r(n,t,e)},curry3ResolveArg2=(r,n,e)=>function(t){return r(n,e,t)},curry3=function(r,n,e,t){return n==__?curry3ResolveArg0(r,e,t):e==__?curry3ResolveArg1(r,n,t):curry3ResolveArg2(r,n,e)},thunkify2=(r,n,e)=>function(){return r(n,e)},thunkify5=(r,n,e,t,o,i)=>function(){return r(n,e,t,o,i)},thunkConditional=(r,n,e)=>r?n():e(),isPromise=r=>null!=r&&"function"==typeof r.then,isArray=Array.isArray,SelfReferencingPromise=function(r){const n=r.then((r=>[r,n]));return n},promiseRace=Promise.race.bind(Promise),asyncArraySome=async function(r,n,e,t){const o=r.length;for(;++e<o;){const o=n(r[e]);if(isPromise(o))t.add(SelfReferencingPromise(o));else if(o)return!0}for(;t.size>0;){const[r,n]=await promiseRace(t);if(t.delete(n),r)return!0}return!1},arraySome=function(r,n){const e=r.length;let t=-1;for(;++t<e;){const e=n(r[t]);if(isPromise(e))return asyncArraySome(r,n,t,new Set([SelfReferencingPromise(e)]));if(e)return!0}return!1},arrayPush=function(r,n){return r.push(n),r},funcConcatSync=(r,n)=>function(...e){return n(r(...e))},noop=function(){},symbolIterator=Symbol.iterator,symbolAsyncIterator=Symbol.asyncIterator,differenceWithArrayAsync=async function(r,n,e,t,o){const i=n.length;for(;++o<i;){const i=n[o];let c=arraySome(e,curry2(r,i,__));isPromise(c)&&(c=await c),c||t.push(i)}return t},differenceWithArray=function(r,n,e){const t=n.length,o=[];let i=-1;for(;++i<t;){const t=n[i],c=arraySome(e,curry2(r,t,__));if(isPromise(c))return c.then(funcConcatSync(curry3(thunkConditional,__,noop,thunkify2(arrayPush,o,t)),thunkify5(differenceWithArrayAsync,r,n,e,o,i)));c||o.push(t)}return o},differenceWith=(r,n)=>function(e){if(isArray(e))return differenceWithArray(r,n,e);throw new TypeError(`${e} is not an Array`)};export default differenceWith;