Introduce TermOperator helper and refactor execute()s to use replaceSubjectMatchingTerm
This commit is contained in:
@@ -17,20 +17,19 @@ export class Unique extends Command<{}> {
|
||||
}
|
||||
|
||||
execute(vm: StrVM): Awaitable<StrVM> {
|
||||
return vm.tapInPlace(ctx =>
|
||||
ctx.replaceSubject(sub => {
|
||||
return vm.replaceContextMatchingTerm({
|
||||
destructured: sub => {
|
||||
const seen: Record<string, boolean> = {}
|
||||
return wrapDestructured(
|
||||
unwrapDestructured(sub)
|
||||
.filter(part => {
|
||||
const hash = hashStrRVal(wrapString(part.value))
|
||||
if ( seen[hash] ) {
|
||||
return false
|
||||
}
|
||||
return sub.filter(part => {
|
||||
const hash = hashStrRVal(wrapString(part.value))
|
||||
if ( seen[hash] ) {
|
||||
return false
|
||||
}
|
||||
|
||||
seen[hash] = true
|
||||
return true
|
||||
}))
|
||||
}))
|
||||
seen[hash] = true
|
||||
return true
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user