Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: async map and filter for arrays with Promise predicates #1

Open
ydanneg opened this issue Feb 20, 2023 · 1 comment
Open

FR: async map and filter for arrays with Promise predicates #1

ydanneg opened this issue Feb 20, 2023 · 1 comment
Assignees

Comments

@ydanneg
Copy link

ydanneg commented Feb 20, 2023

FR: Would be great to have filterAsync and mapSync for arrays that work with Promise predicates.

Example (taken from internet):

async function mapAsync<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]> {
    return Promise.all(array.map(callbackfn))
}

async function filterAsync<T>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]> {
    const filterMap = await mapAsync(array, callbackfn)
    return array.filter((_, index) => filterMap[index])
}
@netknight netknight self-assigned this Feb 20, 2023
@netknight
Copy link
Member

I'll think about it, looks like such a change can lead to whole ArrayLike interface realisation with Promise result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants