This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-03
Channels
- # bangalore-clj (2)
- # beginners (29)
- # boot (52)
- # cider (4)
- # clara (3)
- # cljs-dev (34)
- # cljsjs (7)
- # cljsrn (3)
- # clojure (71)
- # clojure-austin (1)
- # clojure-dev (5)
- # clojure-france (20)
- # clojure-russia (51)
- # clojure-spec (9)
- # clojure-uk (20)
- # clojurescript (131)
- # core-async (56)
- # core-logic (6)
- # cursive (50)
- # datascript (19)
- # datomic (16)
- # dirac (118)
- # emacs (100)
- # events (4)
- # hoplon (14)
- # incanter (1)
- # jobs (7)
- # jobs-discuss (96)
- # jobs-rus (21)
- # lein-figwheel (5)
- # leiningen (21)
- # off-topic (11)
- # om (45)
- # onyx (42)
- # pamela (1)
- # pedestal (22)
- # portland-or (3)
- # re-frame (8)
- # reagent (5)
- # ring (9)
- # robots (1)
- # spacemacs (14)
- # specter (28)
- # sql (2)
- # untangled (165)
Is this a known bug in spec? I'd expect both to return the same thing, but using s/and
with s/keys*
doesn't seem to work.
(s/def ::x int?)
(s/conform (s/cat :a (s/and int? (constantly true))
:x (s/keys* :opt-un [::x]))
[3 :x 3])
;=> {:a 2 :x {:x 3}}
(s/conform (s/cat :a int?
:x (s/and (s/keys* :opt-un [::x]) (constantly true)))
[3 :x 3])
;=> :clojure.spec/invalid
@madstap by wrapping your keys*
spec with and
, I believe it's no longer a regex spec
(s/conform (s/cat :a int?
:x (s/and (s/keys* :opt-un [::x]) (constantly true)))
[3 [:x 3]])
;=> {:x {:x 3}, :a 3}
correct - use s/&
instead to add a predicate but keep it as a regex op
the and spec above would be looking for data like [3 [:x 3]]
This is on HN right now. I’ve read the intro & it’s pretty awesome: https://www.cl.cam.ac.uk/~sd601/thesis.pdf — of interest to anybody doing static analysis with spec, or just generally interested in both open/extensible and types
hiya - beginning to add spec to a preexisting project, and i’m running into this situation: i’m trying to spec some “event” maps, which have required keys including :type
(eg one of :foo, :bar, :baz) and :data
.
and the thing is that when :type
is :foo
, :data
is a map that looks like {:a 1 :b 2}
;
and when :type
is :bar
, :data
is a map that looks like {:c 3 :b 4}
;
and when :type
is :baz
, :data is a number like 1234
,
etc.
what do i want in this situation - is this the exact situation where i should reach for a multi-spec?
i’m beginning to think that having :data
be the name for several different categories of thing will be a problem there