This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-28
Channels
- # announcements (2)
- # babashka (16)
- # bangalore-clj (1)
- # beginners (93)
- # boot (11)
- # calva (5)
- # cider (13)
- # clj-kondo (49)
- # cljdoc (14)
- # cljs-dev (1)
- # clojure (99)
- # clojure-dev (3)
- # clojure-europe (1)
- # clojure-india (1)
- # clojure-italy (9)
- # clojure-nl (3)
- # clojure-poland (1)
- # clojure-russia (1)
- # clojure-spec (31)
- # clojure-uk (21)
- # clojured (2)
- # clojurescript (18)
- # core-async (12)
- # cursive (36)
- # data-science (1)
- # datomic (54)
- # duct (3)
- # emacs (33)
- # events (1)
- # fulcro (17)
- # jobs (1)
- # joker (8)
- # keechma (1)
- # leiningen (7)
- # malli (8)
- # nrepl (19)
- # pathom (6)
- # planck (18)
- # re-frame (20)
- # reagent (18)
- # shadow-cljs (3)
- # sql (7)
- # vim (31)
currently, no. we will probably have both flowing and unflowing forms in spec 2
you might get away with moving spec to the last position in the s/and, depending on resilience of your predicates to random input. @kenny or, if this is the only place you use predicates – make them expect conformed value
Hmm. Can't do the latter because the predicates are used on the regular form of the data too.
you could wrap s/nonconforming
around each pred
(s/def ::base-metric
(s/and
(s/nonconforming ::metric/metric)
(s/nonconforming metric-bounds-lower-less-than-or-equal-to-upper?)
(s/nonconforming metric-default-value-within-bounds?)))
something like that
This is going to make things so much cleaner! Thanks @alexmiller 😃
(defmacro and2
[& pred-forms]
(let [pred-forms (map (fn [pred-form]
`(s/nonconforming ~pred-form)) pred-forms)]
`(s/and ~@pred-forms)))
Per the description of every
, the :kind
pred "must generate in order for every to generate". I see that preds like set?
can generate, e.g., (gen/sample (s/gen (s/spec set?)))
, but I'm at a loss as to how to provide generators for custom preds.
there is no open mechanism to bind generators to custom preds currently
you can provide the :kind pred as a separate spec outside s/every too
(s/and (s/with-gen my-pred ...) (s/every ...))
that said, what kind of pred are you using that's not a core pred?
prob easier to attach a generator to the overall spec
I think uuid? has a generator? or maybe that's just one we've talked about
yeah, uuid? gens
you can generally wrap specs with custom generators around preds with s/with-gen or s/spec
the particular case of :kind in s/every is a place where you don't have that opportunity
yep, it's thunked to make the load step dynamic and optional