export const asyncFind = async ( array: Array, predicate: (element: Element) => Promise ) => { const index = (await Promise.allSettled(array.map(predicate))) .map((result, index) => { if (result.status === "fulfilled") { return result.value; } else throw new Error(`asyncFind rejected predicate at index ${index}`); }) .findIndex(Boolean); return array[index]; };