This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-22
Channels
- # aleph (6)
- # announcements (1)
- # babashka (2)
- # beginners (51)
- # calva (14)
- # cider (1)
- # clj-kondo (15)
- # cljs-dev (2)
- # cljsrn (1)
- # clojure (9)
- # clojure-czech (2)
- # clojure-spec (5)
- # clojure-uk (45)
- # clojuredesign-podcast (2)
- # clojurescript (4)
- # clojutre (3)
- # cursive (4)
- # datomic (8)
- # duct (8)
- # jackdaw (1)
- # joker (1)
- # keechma (1)
- # off-topic (127)
- # om (1)
- # reagent (1)
- # reitit (6)
- # shadow-cljs (22)
- # testing (3)
Hi y'all... I'm a beginner tinkering around with spec (on CLJS) and I was wondering: is there a way to encode a spec so that a certain keyset is required only if another key has a certain value? For example, I might have {:type :assignment, :left ..., :right ...}
or {:type :identifier, :name 'some-name}
; could I express the requirement that :left
and :right
must both appear iff :type
is :assignment
?
Wait, I think I figured it out... I'm guessing
(defn node-is? [type] #(= (:type %) type))
(s/or
(s/keys :req-un [::type (node-is? :assignment) ::left ::right])
(s/keys :req-un [::type (node-is? :identifier) ::name]))
@sebastiano.barrera_cl I think what you need is multi-spec
Oh, let me take a look at that