From 6ef3d9cd3204b9f8d9044333db3e3a84730747be Mon Sep 17 00:00:00 2001 From: Michael Mairegger Date: Fri, 24 May 2024 12:11:01 +0200 Subject: [PATCH] Remove continue label Fixes #29 --- src/async/_private/distinctAsync.ts | 14 ++++++++------ src/parallel/_private/distinctAsync.ts | 12 +++++++----- src/sync/_private/distinctAsync.ts | 16 +++++++++------- 3 files changed, 24 insertions(+), 18 deletions(-) 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 + } } }