How to make custom selectors?

Is it possible to make a reusable show query that would achieve the same thing as this?

show metadata: metadata => {
  if {
    // some function that return a boolean
    not is-metadata-with-id(metadata)
  } or {
    // another arbitrary boolean function
    metadata.value.id != tag("xlink")
  } {
    // skip
    return metadata
  }
  // start actual show rule
}

Truly custom selectors (I think that’s the word you’re looking for, maybe edit it in the title) are not supported, but you can probably use the technique shown here: How can I create show rules in a loop? - #2 by SillyFreak

In that post’s example, you first go from

#show "foo": strong
#show "baz": strong

to

#show: body => {
  show "foo": strong
  show "baz": strong

  body
}

The benefit is that now you don’t need to handle show rules as values, but a function, and Typst is functional and can thus do that.

You would want to go from

#show metadata: metadata => ...

to

#show: metadata-with-id("xlink", metadata => ...)

I’ll leave writing metadata-with-id for you, but I can also help if you need it.