-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
I often have to filter a list but may need todo an async request to determine if an item should be kept or not (e.g. checking existence of an item in a database).
Adding a new filter function similar to the already existing map function within radashi would be helpful. Something along the lines of:
export async function filter<T>(
array: readonly T[],
asyncFilterFunc: (item: T, index: number) => PromiseLike<boolean>,
): Promise<K[]> {
if (!array) {
return []
}
const result = []
let index = 0
for (const value of array) {
const keepValue = await asyncFilterFunc(value, index++)
if (keepValue) {
result.push(newValue)
}
}
return result
}If this seems like it can be added to radashi, then I can open a PR with the implementation + tests.
Metadata
Metadata
Assignees
Labels
No labels