Introduce TermOperator helper and refactor execute()s to use replaceSubjectMatchingTerm
This commit is contained in:
@@ -19,10 +19,10 @@ export class Contains extends Command<{ find: StrTerm }> {
|
||||
}
|
||||
|
||||
execute(vm: StrVM, data: { find: StrTerm }): Awaitable<StrVM> {
|
||||
return vm.tapInPlace(ctx =>
|
||||
ctx.replaceSubjectAsString(sub =>
|
||||
sub.includes(ctx.resolveString(data.find))
|
||||
? sub
|
||||
: ''))
|
||||
return vm.replaceContextMatchingTerm(ctx => ({
|
||||
string: sub => sub.includes(ctx.resolveString(data.find)) ? sub : '',
|
||||
destructured: parts => parts.filter(part =>
|
||||
part.value.includes(ctx.resolveString(data.find))),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user