Skip to content

Instantly share code, notes, and snippets.

@junhoyeo
Created October 9, 2022 13:16
Show Gist options
  • Save junhoyeo/2816d42cce84e28b49105eef00418626 to your computer and use it in GitHub Desktop.
Save junhoyeo/2816d42cce84e28b49105eef00418626 to your computer and use it in GitHub Desktop.
const asyncFlatMap = async <T extends any, U extends any>(
array: T[],
callback: (value: T, index: number, array: T[]) => Promise<[] | U | U[]>,
): Promise<U[]> => {
const result = await Promise.all(array.map(callback));
return result.flat() as U[];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment