import {Command, hashStrRVal, ParseContext, unwrapDestructured, wrapDestructured, wrapString} from "./command.js"; import {LexInput} from "../lexer.js"; import {StrVM} from "../vm.js"; import {Awaitable} from "../../util/types.js"; export class Unique extends Command<{}> { isParseCandidate(token: LexInput): boolean { return this.isKeyword(token, 'unique') } attemptParse(context: ParseContext): {} { return {} } getDisplayName(): string { return 'unique' } execute(vm: StrVM): Awaitable { return vm.tapInPlace(ctx => ctx.replaceSubject(sub => { const seen: Record = {} return wrapDestructured( unwrapDestructured(sub) .filter(part => { const hash = hashStrRVal(wrapString(part.value)) if ( seen[hash] ) { return false } seen[hash] = true return true })) })) } }