Skip to content

Supertype selection

There are times when the value you're searching for can appear in different types, like string and template literals, and because SYNG selectors are bound to the type in which a value appears (like (str) and (tpl) respectively), you need to resort to unions to select the value in either type:

clojure
(:or (str "foo")
     (tpl "foo"))
(:or (str "foo")
     (tpl "foo"))

SYNG provides an ergonomic interface for this use case in the form of supertype selectors, or ones that span a value across distinct - yet related - types. Here is one such selector for the case mentioned earlier, (str+):

clojure
(str+ foo)
(str+ foo)

Which would match both "foo" and `foo` without resorting to a union.

Supertype selectors (or superselectors for short) are denoted with a trailing + to express that they match more than one type. As with macros, they expand to multiple selectors, only that they are pre-defined by SYNG for your convenience.

If you find a particular pattern to be common enough to warrant its own superselector, please file a feature request with the use case to help us add it!

Copyright © 2022-present Semantic Works, Inc.