Fork me on GitHub
#beginners
<
2023-11-11
>
sheluchin17:11:55

If I define a map spec like (s/keys :req [:x/y]), is there a way to get an equivalent spec from it, where the keys are not namespaced (`:req-un`)?

Bob B17:11:09

I'm not aware of a direct spec transformation of this nature, but I think describe could be used to get a data description of the spec back, and then a related spec could be constructed using that description

sheluchin18:11:59

Probably simpler to just define the key vector in its own def and re-use that with :req and :req-un.

Bob B18:11:29

almost definitely... I got the impression the starting point was a spec

Alex Miller (Clojure team)18:11:38

you can't actually do that as s/keys is a macro and expects a literal vector there

Alex Miller (Clojure team)18:11:50

but you can macro around s/def

sheluchin18:11:31

I stand corrected. Probably simpler to just repeat the vector then. That's a noteworthy gotcha.