Created
November 20, 2018 04:02
-
-
Save maruware/402c4ff49a658537dc327b2fb3003f9e to your computer and use it in GitHub Desktop.
TypeScript: find map value with promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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