Fork me on GitHub
#clojure-spec
<
2024-01-04
>
jjttjj15:01:52

I'm a bit rusty with spec. Is there a "trick" to get generators working across s/and? I think I get why it must behave like this, and can think of a few ways to do this but not sure the best or if there's some built-in shortcut in the generators library. Or is it better just to keep s/keys specs "top level" when possible?

(s/def ::x string?)
  (s/def ::y keyword?)
  (s/def ::a (s/keys :req [::x]))
  (s/def ::b (s/keys :req [::y]))
  (s/exercise ::a) ;;works
  (s/exercise ::b) ;;works
  (s/exercise (s/and ::a ::b)) ;;ExceptionInfo Couldn't satisfy such-that predicate after 100 tries.

1
jjttjj16:01:08

Ah yes perfect, thanks!

👍 1
Alex Miller (Clojure team)16:01:27

yes, merge is what you want here