Fix AsyncCollection.filter to allow for async filter functions

master
Garrett Mills 2 years ago
parent fd77ad5cd3
commit de13030815

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.9.40",
"version": "0.9.41",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

@ -401,7 +401,17 @@ export class AsyncCollection<T> {
let newItems: CollectionItem<T>[] = []
await this.inChunks(async items => {
newItems = newItems.concat(items.filter(func).all())
const filterItems: CollectionItem<T>[] = []
for ( let i = 0; i < items.length; i += 1 ) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const item = items.get(i)!
if ( await func(item, i) ) {
filterItems.push(item)
}
}
newItems = newItems.concat(filterItems)
})
return new Collection<T>(newItems)

Loading…
Cancel
Save