UNPKG

rubico

Version:

[a]synchronous functional programming

9 lines (7 loc) 1.64 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. */ !function(n,t){"object"==typeof module?module.exports=t:"function"==typeof define?define((()=>t)):n.find=t}("object"==typeof globalThis?globalThis:this,function(){"use strict";const n=Array.isArray,t=Symbol.iterator,e=Symbol.asyncIterator,o=Object.values,r=n=>null!=n&&"function"==typeof n.then,u=Symbol.for("placeholder"),f=function(n,t,e,o){return t==u?((n,t,e)=>function(o){return n(o,t,e)})(n,e,o):e==u?((n,t,e)=>function(o){return n(t,o,e)})(n,t,o):((n,t,e)=>function(o){return n(t,e,o)})(n,t,e)},i=(n,t,e,o)=>function(){return n(t,e,o)},c=(n,t,e)=>n?t():e(),l=n=>function(){return n},a=async function(n,t,e){const o=n.length;for(;++e<o;){const o=n[e];let u=t(o);if(r(u)&&(u=await u),u)return o}},s=function(n,t){const e=n.length;let o=-1;for(;++o<e;){const e=n[o],s=t(e);if(r(s))return s.then(f(c,u,l(e),i(a,n,t,o)));if(s)return e}},y=(n,t,e)=>function(){return n(t,e)},d=async function(n,t){let e=n.next();for(;!e.done;){const o=e.value;let u=t(o);if(r(u)&&(u=await u),u)return o;e=n.next()}};return i=>function(a){return n(a)?s(a,i):null!=a?"function"==typeof a[t]?function(n,t){let e=n.next();for(;!e.done;){const o=e.value,i=t(o);if(r(i))return i.then(f(c,u,l(o),y(d,n,t)));if(i)return o;e=n.next()}}(a[t](),i):"function"==typeof a[e]?async function(n,t){let e=await n.next();for(;!e.done;){const o=e.value;let u=t(o);if(r(u)&&(u=await u),u)return o;e=await n.next()}}(a[e](),i):"function"==typeof a.find?a.find(i):a.constructor==Object?s(o(a),i):void 0:void 0}}());