This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-15
Channels
- # beginners (15)
- # boot (4)
- # cider (1)
- # cljsrn (16)
- # clojars (1)
- # clojure (92)
- # clojure-india (3)
- # clojure-russia (27)
- # clojure-spec (9)
- # clojure-uk (5)
- # clojurescript (73)
- # cursive (28)
- # datascript (10)
- # emacs (1)
- # events (5)
- # hoplon (1)
- # instaparse (7)
- # juxt (2)
- # klipse (13)
- # lumo (17)
- # off-topic (166)
- # onyx (4)
- # protorepl (5)
- # re-frame (5)
- # reagent (13)
- # rum (26)
- # untangled (17)
- # yada (3)
(s/and (s/keys ...) #(xor ... %))
Not that xor is a thing, but you get the idea
A concrete example from our codebase @stand
(s/def :criteria/general (s/and (s/keys :req-un [(or :criteria-item/value :criteria-item/values)
:criteria-item/weight])
#(not (and (:value %) (:values %)))))
A general criteria map must have :weight
but can only have one of :value
or :values
.
I don't believe that would work in my case. I need a situation where neither :value
or :values
need appear but if one appears the other cannot. I don't think you can do an or
in a keys :opt
, can you?
Ah, no, you cannot.
But they would both just be :opt
keys and you could still s/and
the check that they are not both present
like this
(s/def :criteria/general (s/and (s/keys :opt-un [:criteria-item/value :criteria-item/values
:criteria-item/weight])
#(not (and (:value %) (:values %)))))
That would work for the neither case, the either case, and prevent the both case I think?