Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/async/_private/distinctAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ export const distinctAsync = <TSource>(

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
}
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/parallel/_private/distinctAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ export const distinctAsync = <TSource>(
comparer: IAsyncEqualityComparer<TSource>): IParallelEnumerable<TSource> => {
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
Expand Down
16 changes: 9 additions & 7 deletions src/sync/_private/distinctAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ export const distinctAsync = <TSource>(

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
}
}
}

Expand Down