Skip to content

Instantly share code, notes, and snippets.

@maruware
Created November 20, 2018 04:02
Show Gist options
  • Save maruware/402c4ff49a658537dc327b2fb3003f9e to your computer and use it in GitHub Desktop.
Save maruware/402c4ff49a658537dc327b2fb3003f9e to your computer and use it in GitHub Desktop.
TypeScript: find map value with promise
const findMapPromises = async <T, S> (arr: T[], predicate: (value: T, index: number, obj: T[]) => Promise<S>): Promise<S> => {
for (let i = 0; i < arr.length; i++) {
try {
const r = await predicate(arr[i], i, arr)
return r
} catch (e) {
// next.
}
}
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment