From de13030815c9bd9d1c2ba3958f3c5dd3054c673b Mon Sep 17 00:00:00 2001 From: garrettmills Date: Thu, 28 Apr 2022 19:41:04 -0500 Subject: [PATCH] Fix AsyncCollection.filter to allow for async filter functions --- package.json | 2 +- src/util/collection/AsyncCollection.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 58d28c9..468a249 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/util/collection/AsyncCollection.ts b/src/util/collection/AsyncCollection.ts index 0accd4d..3be9462 100644 --- a/src/util/collection/AsyncCollection.ts +++ b/src/util/collection/AsyncCollection.ts @@ -401,7 +401,17 @@ export class AsyncCollection { let newItems: CollectionItem[] = [] await this.inChunks(async items => { - newItems = newItems.concat(items.filter(func).all()) + const filterItems: CollectionItem[] = [] + + 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(newItems)