This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-13
Channels
- # announcements (1)
- # babashka (41)
- # beginners (194)
- # calva (14)
- # chlorine-clover (2)
- # cider (32)
- # circleci (9)
- # cljsrn (10)
- # clojure (110)
- # clojure-australia (1)
- # clojure-berlin (2)
- # clojure-dev (39)
- # clojure-europe (42)
- # clojure-france (3)
- # clojure-nl (19)
- # clojure-spec (22)
- # clojure-uk (23)
- # clojurescript (21)
- # conjure (41)
- # datomic (33)
- # depstar (16)
- # duct (46)
- # events (1)
- # fulcro (17)
- # graphql (14)
- # jobs (6)
- # jobs-discuss (9)
- # leiningen (6)
- # malli (29)
- # off-topic (21)
- # pathom (7)
- # portal (1)
- # rdf (81)
- # re-frame (3)
- # reagent (12)
- # reitit (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (60)
- # specter (1)
- # sql (13)
- # tools-deps (23)
- # vrac (1)
- # yada (19)
oh, hmm:
; (#:scratch{:keys [scratch/total prices]}) - failed: Extra input at: [:fn-tail :arity-1 :params] spec: :clojure.core.specs.alpha/param-list
#:scratch{:keys [scratch/total prices]} - failed: vector? at: [:fn-tail :arity-n :params] spec: :clojure.core.specs.alpha/param-list
is there an fdef
that works for multi-methods?
no, but you can pull the dispatch function out and spec that
thank you!
ya, dunno what was up with that destructuring, but this works:
(s/def ::m (s/and (s/keys :req [::total ::prices])
#(= (::total %) (reduce + (::prices %)))))
ah-ha! I think I got it! thx @alexmiller!
I did something like this:
(s/def ::m (s/and ::total=prices (s/schema [::prices ::total])))
just as a heads up, I do not consider spec 2 to be ready for use and the api may change before release
I have the following spec:
(s/def ::grid
(-> (s/keys :opt-un [::grid])
(s/coll-of :kind vector? :min-count 1)
(s/coll-of :kind vector? :min-count 1)))
How do I do generative testing with this kind of spec? any attempt to generate an example of ::grid
makes my OS super laggy until I kill the JVM process...that's not a valid spec? what are you expecting -> to do there?
Oh, sorry, I added threading in the message for readability, actual spec doesn't have it
I guess maybe it would work in the spec 1 macrology, but I find that very confusing to parse (and it won't in spec 2 I think)
in general, setting :gen-max is useful for coll specs though to bound nested coll size
We often build our own spec "types" by doing something like this.
(defmacro my-custom-map
[kpred vpred]
(let [form `(s/map-of ~kpred ~vpred)]
`(s/with-gen ~form #(gen/fmap identity (s/gen ~form)))))
(s/def ::k string?)
(s/def ::v string?)
(s/def ::my-custom-map (my-custom-map ::k ::v))
This, however, does not play nice with :gen overrides.
(gen/generate (s/gen ::my-custom-map {::k #(s/gen #{"a" "b"})}))
=>
{"3" "b4tq9FeW6Gt",
"8h" "o47F763P0v5B63sA52c4xu1FN",
...}
Is there a better way of doing this that works with :gen overrides?This seems to be a common pattern: https://stackoverflow.com/questions/43230546/a-clojure-spec-that-matches-and-generates-an-ordered-vector-of-variable-length
It's like with-gen
needs to take an argument with :gen overrides or implicitly use a dynamic variable.