UNPKG

rubico

Version:

[a]synchronous functional programming

8 lines (7 loc) 1.03 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 isArray=Array.isArray,isPromise=r=>null!=r&&"function"==typeof r.then,thunkConditional=(r,n,e)=>r?n():e(),__=Symbol.for("placeholder"),always=r=>function(){return r},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)},thunkify3=(r,n,e,t)=>function(){return r(n,e,t)},findIndexAsync=async function(r,n,e){const t=n.length;for(;++e<t;){let t=r(n[e]);if(isPromise(t)&&(t=await t),t)return e}return-1},findIndex=r=>function(n){const e=n.length;let t=-1;for(;++t<e;){const e=r(n[t]);if(isPromise(e))return e.then(curry3(thunkConditional,__,always(t),thunkify3(findIndexAsync,r,n,t)));if(e)return t}return-1};export default findIndex;