diff --git a/src/async/_private/distinctAsync.ts b/src/async/_private/distinctAsync.ts index c246673..e340c12 100644 --- a/src/async/_private/distinctAsync.ts +++ b/src/async/_private/distinctAsync.ts @@ -7,17 +7,19 @@ export const distinctAsync = ( async function* iterator() { const distinctElements: TSource[] = [] - outerLoop: for await (const item of source) { + let found = false for (const distinctElement of distinctElements) { - const found = await comparer(distinctElement, item) - if (found) { - continue outerLoop + if (await comparer(distinctElement, item)) { + found = true + break } } - distinctElements.push(item) - yield item + if (!found) { + distinctElements.push(item) + yield item + } } } diff --git a/src/parallel/_private/distinctAsync.ts b/src/parallel/_private/distinctAsync.ts index 1b383c4..e0404a8 100644 --- a/src/parallel/_private/distinctAsync.ts +++ b/src/parallel/_private/distinctAsync.ts @@ -6,16 +6,18 @@ export const distinctAsync = ( comparer: IAsyncEqualityComparer): IParallelEnumerable => { const generator = async () => { const distinctElements: TSource[] = [] - outerLoop: for (const item of await source.toArray()) { + let found = false for (const distinctElement of distinctElements) { - const found = await comparer(distinctElement, item) - if (found) { - continue outerLoop + if (await comparer(distinctElement, item)) { + found = true + break } } - distinctElements.push(item) + if (!found) { + distinctElements.push(item) + } } return distinctElements diff --git a/src/sync/_private/distinctAsync.ts b/src/sync/_private/distinctAsync.ts index b14d774..e627802 100644 --- a/src/sync/_private/distinctAsync.ts +++ b/src/sync/_private/distinctAsync.ts @@ -7,17 +7,19 @@ export const distinctAsync = ( async function* iterator() { const distinctElements: TSource[] = [] - outerLoop: - for (const item of source) { + for await (const item of source) { + let found = false for (const distinctElement of distinctElements) { - const found = await comparer(distinctElement, item) - if (found) { - continue outerLoop + if (await comparer(distinctElement, item)) { + found = true + break } } - distinctElements.push(item) - yield item + if (!found) { + distinctElements.push(item) + yield item + } } }