Fork me on GitHub
#clojure-spec
<
2018-05-11
>
cap10morgan19:05:12

Anyone know why the default generator for (s/map-of keyword? string?) would take 10+ seconds to generate 1,000 samples?

ghadi19:05:41

it's generating large maps. set (s/map-of .... :gen-max 2) to constrain sizes

cap10morgan19:05:17

Ah, cool. I hadn't looked for that option in the spec fn itself. Thanks @ghadi.

ghadi19:05:37

(doc s/every) will show some others

👍 4
ambroise22:05:21

I have this spec

(s/def ::foo (s/keys :req-un [::zipcode
                              ::state
                              ::bar
                              ::baz]
And I’d like to force zipcode and state to be consistent (i have a zipcode->state function so if they are both present, they need to match) How can I write my ::zipcode and ::state specs?

Alex Miller (Clojure team)22:05:52

(s/def ::foo' (s/and ::foo (fn [{:keys [state zipcode]}] (= state (zipcode->state zipcode)))

Alex Miller (Clojure team)22:05:15

wrap your ::foo in another spec that combines it with a custom predicate to ensure the zip code constraint

ambroise22:05:48

awesome, thanks!