Created
June 7, 2023 04:48
filterAsync.ts
This file contains hidden or 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 filterAsync = <T>(arr: T[], fn: (x: T) => Promise<boolean>) => | |
mapAsync(arr, fn).then((arr2) => arr.filter((_, i) => Boolean(arr2[i]))); | |
(async () => { | |
console.log("START FILTER"); | |
const filtered = await filterAsync([1, 2, 3, 4], async (n) => { | |
const x = await fakeFilter(n); | |
return x; | |
}); | |
useResult(filtered); | |
console.log("END FILTER"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment