Fork me on GitHub
#clojure-spec
<
2018-07-22
>
alex-dixon04:07:10

Is it possible to define a spec with a custom generator but have it separate from the spec itself? Something like

(s/def ::my-spec (s/or :keyword keyword? :symbol symbol?))
(s/with-gen ::my-spec (gen/symbol))
Seems like it could be looking at the defn for s/with-gen but not working at the REPL atm…

athos04:07:52

You can replace spec generator impls with s/gen's overrides argument or via :gen option of instrument and check.

athos04:07:47

A library of mine called Genman also does that well https://github.com/athos/genman If you're instested, give it a shot 😉

alex-dixon05:07:03

Works!

(gen/generate
    (s/gen ::my-spec
           {::my-spec gen/symbol}))

alex-dixon05:07:11

@athos You’re awesome. Thank you 🙂

rich 4