You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: narrow the arrays so these functions work with compiletime array literals
returnresultasnever}/** * the return type of {@link findNotUndefined} and {@link findNotUndefinedAsync} when a callback is not provided * * ie. guaranteed to not be `undefined` or `null` if a result was found */typeFindNotUndefinedResult<T>=|Exclude<FindResult<NonNil<Awaited<T>>>,undefined>|(undefinedextendsAwaited<T> ? undefined : nullextendsAwaited<T> ? undefined : never)// TODO: narrow the arrays so these functions work with compiletime array literals/** * finds the first item in an array where the given callback doesn't return `null` or `undefined` * @param arr the array of `T`s to check * @param callback a function to run on `arr` that may return `null` or `undefined`. * @param runAtTheSameTime whether to execute the `callback` on each element of `arr` at the same time */exportconstfindNotUndefinedAsync: {<Textendsunknown[]>(arr: T,runAtTheSameTime: boolean,callback: (it: T[number])=>Promise<unknown>,): Promise<FindResult<T[number]>><Textendsunknown[]>(arr: T,runAtTheSameTime: boolean): Promise<FindNotUndefinedResult<T[number]>>}=async<Textendsunknown[]>(arr: T,runAtTheSameTime: boolean,callback: (it: T[number])=>Promise<unknown>=(value)=>Promise.resolve(value),): Promise<FindResult<T[number]>>=>{if(runAtTheSameTime){returnfind(arr,async(value)=>!isNullOrUndefined(awaitcallback(value)))asnever}// hack so the compiler knows index is within the range of arrfor(letindex: Keys<T>=0asnever;index<arr.length;(indexasnumber)++){constvalue=arr[index]constresult=awaitcallback(value)if(result)return{ result, index }asnever}return}/** * finds the first item in an array where the given callback doesn't return `null` or `undefined` * @param arr the array of `T`s to check * @param callback a function to run on `arr` that may return `null` or `undefined`. */exportconstfindNotUndefined: {<Textendsunknown[]>(arr: T,callback: (it: T[number])=>unknown): FindResult<T[number]><Textendsunknown[]>(arr: T): FindNotUndefinedResult<T[number]>}=<Textendsunknown[]>(arr: T,callback: (it: T[number])=>unknown=(value)=>value,): FindResult<T[number]>=>{// hack so the compiler knows index is within the range of arrfor(letindex: Keys<T>=0asnever;index<arr.length;(indexasnumber)++){constvalue=arr[index]constresult=callback(value)if(!isNullOrUndefined(result))return{ result, index }asnever}return}
The text was updated successfully, but these errors were encountered:
ts-helpers/src/utilityFunctions/Array.ts
Line 145 in 1e999c7
The text was updated successfully, but these errors were encountered: