This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-02
Channels
- # asami (24)
- # babashka (85)
- # beginners (137)
- # calva (46)
- # cider (16)
- # clj-kondo (19)
- # cljs-dev (7)
- # clojure (13)
- # clojure-australia (1)
- # clojure-europe (10)
- # clojure-nl (4)
- # clojure-spec (6)
- # clojure-uk (3)
- # clojurescript (5)
- # conjure (21)
- # cursive (15)
- # datascript (46)
- # datomic (13)
- # depstar (32)
- # figwheel-main (1)
- # fulcro (6)
- # honeysql (20)
- # lsp (53)
- # malli (7)
- # meander (9)
- # off-topic (35)
- # other-languages (1)
- # polylith (41)
- # re-frame (5)
- # reagent (4)
- # releases (3)
- # rewrite-clj (2)
- # shadow-cljs (22)
- # spacemacs (15)
- # tools-deps (3)
- # xtdb (17)
(s/def :corp/employee
(s/keys :req [:employee/first-name]))
(s/def :employee/first-name string?)
(s/def :favorite/ice-cream #{:chocolate :vanilla})
(e/expound :corp/employee {:employee/first-name "michael"
:favorite/ice-cream :strawberry})
;; -- Spec failed --------------------
;; {:employee/first-name ...,
;; :favorite/ice-cream :strawberry}
;; ^^^^^^^^^^^
;; should be one of: :chocolate, :vanilla
;; -- Relevant specs -------
;; :favorite/ice-cream:
;; #{:chocolate :vanilla}
;; :corp/employee:
;; (clojure.spec.alpha/keys :req [:employee/first-name])
;; -------------------------
;; Detected 1 error
I find this pretty surprisinggiven that the :corp/employee
spec doesn't say anything about ice cream
That is by design in Spec — and the reference docs on http://clojure.org talk about that. I think the rationale may do too.
thanks Sean - i'll take a look
https://clojure.org/guides/spec#_entity_maps says “When conformance is checked on a map, it does two things - checking that the required attributes are included, and checking that every registered key has a conforming value. We’ll see later where optional attributes can be useful. Also note that ALL attributes are checked via keys, not just those listed in the :req and :opt keys. Thus a bare (s/keys) is valid and will check all attributes of a map without checking which keys are required or optional.”
yeah, there it is. checks that every registered key has a conforming value. good to know