This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-31
Channels
- # architecture (5)
- # beginners (35)
- # boot (150)
- # cider (1)
- # clara (7)
- # cljs-dev (131)
- # cljsrn (10)
- # clojure (76)
- # clojure-austin (3)
- # clojure-berlin (1)
- # clojure-brasil (1)
- # clojure-chicago (2)
- # clojure-dusseldorf (1)
- # clojure-italy (30)
- # clojure-nl (2)
- # clojure-russia (40)
- # clojure-serbia (2)
- # clojure-spec (25)
- # clojure-uk (13)
- # clojured (2)
- # clojurescript (106)
- # core-async (29)
- # datascript (65)
- # datomic (38)
- # emacs (8)
- # funcool (8)
- # hoplon (6)
- # jobs (3)
- # klipse (93)
- # luminus (16)
- # lumo (4)
- # off-topic (2)
- # om (11)
- # onyx (13)
- # pedestal (4)
- # protorepl (3)
- # re-frame (40)
- # reagent (31)
- # ring (6)
- # ring-swagger (4)
- # slack-help (5)
- # spacemacs (13)
- # untangled (17)
- # vim (2)
Hello, I have newbie question for spec. Let’s suppose I have map {"first-name" “name”}
, can you please show the spec which check key (= ”first-name”) and if the is string. Thanks
Thing I cannot understand here, that if I had keyword instead of “first-name” everything would be trivial:
(s/def :first-name string?)
(s/valid? (s/keys :req-un [:first-name]) {:first-name “name”}) ;=> true
But if “first-name” I cannot attach spec to itif you are doing this just for experimentation -- then
(s/def ::str-str-map #(string? (get % "first-name")))
(s/valid? ::str-str-map {"first-name" "josh"})
but in practice, this only makes life difficult. there's not a way i know of to do this cleanly, as spec is not trying to promote this type of behavior@joshjones got it, thanks!
it's quite difficult to figure out what other options stest/check
accepts in the :clojure.spec.test.check/opts
key
the doc string says: "::stc/opts opts to flow through test.check/quick-check" but it's not really clear which function this refers to
I can go to the source and see it calls stest/check-1
, which calls a private function stest/quick-check
which calls clojure.spec.gen/quick-check
which calls clojure.test.check/quick-check
which tells me the keys are :seed
and :num-tests
, so as far as I can tell :seed
is the only other option it accepts
I wish the doc-string for stest/check
just told me this right away because I might not have clojure.test.check
required and so I need to dig quite deep to find the information
the same goes for s/coll-of
which tells me it accepts the same options as every
, rather than just telling what those options are
or am I missing something obvious? using instance?
as a basic example my spec is actually a bit more complex than that
(defn validate-a-thing [type] (s/spec #(instance? type %))
works well enough but the error suffers as it is always fails predicate: (instance? type %)
can't find an obvious way to provide custom explain
logic, don't care about the gen
part in this case
Shouldn’t my generator be good enough to be used to check
the corresponding function against it’s spec?
(frequencies (map (partial s/valid? (s/and ::matrix
::non-zero-row-sums)) (gen/sample (matrix-gen) 100)))
;; => {true 27, false 73}
I end up with ExceptionInfo Couldn't satisfy such-that predicate after 100 tries. clojure.core/ex-info (core.clj:4725)
again and again.@thheller Yeah you are right, validate-a-thing
needs to be a macro to achieve what you want
@thheller I don't think you're missing anything
@thheller See this paragraph for the rationale: https://clojure.org/about/spec#_code_is_data_not_vice_versa
I’d really appreciate some feedback on this: https://groups.google.com/forum/#!topic/clojure/wwJVJKtxps8
this exact situation has come up several times here @uwo — unfortunately, there’s not much you can do other than what you’ve already identified, at least, none that I’m aware of. The reality is that you do not have one set of billed-charges
; you have two, which means you will need to spec two, whether that’s through a multi-spec or explicit naming
@joshjones thanks, and yes, many many levels of nesting