This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-14
Channels
- # aleph (2)
- # asami (1)
- # aws (6)
- # beginners (65)
- # cider (12)
- # clj-kondo (11)
- # cljs-dev (1)
- # clojure (179)
- # clojure-dev (15)
- # clojure-europe (5)
- # clojure-losangeles (5)
- # clojure-nl (1)
- # clojure-spec (6)
- # clojuredesign-podcast (50)
- # clojurescript (27)
- # cryogen (31)
- # data-science (10)
- # emacs (2)
- # events (1)
- # fulcro (39)
- # helix (4)
- # luminus (3)
- # malli (5)
- # nrepl (4)
- # off-topic (3)
- # pathom (1)
- # reveal (10)
- # shadow-cljs (5)
- # spacemacs (3)
- # tools-deps (6)
- # vscode (1)
- # xtdb (3)
Schema
knows now the IntoSchema
that creates it. Fixes the issue @maciej.falski and makes schema copying (= all utils) faster.
👍 3
two ways to create reusable rules for mutually exclusive keys for maps: 1. just data:
(defn exclusive-keys [keys]
[:fn {:error/message (str "the following keys are mutually exclusive: " (str/join ", " keys))}
(fn [m] (not (every? (partial contains? m) keys)))])
(-> [:and
[:map
[:foo {:optional true} :int]
[:blabla {:optional true} :int]
[:hah {:optional true} :int]
[:bar {:optional true} :int]]
(exclusive-keys [:hah :bar])
(exclusive-keys [:hah :foo])]
(m/explain {:foo 1 :hah 2})
(me/humanize))
; => #:malli{:error ["the following keys are mutually exclusive: :hah, :foo"]}
2. new Schema
impl (with pretty form):
(def Exclusive
(m/-simple-schema
(fn [_ [keys]]
{:type 'Exclusive
:min 1
:max 1
:pred (fn [m] (not (every? (partial contains? m) keys)))
:type-properties {:error/message (str "the following keys are mutually exclusive: " (str/join ", " keys))}})))
(-> [:and
[:map
[:foo {:optional true} :int]
[:blabla {:optional true} :int]
[:hah {:optional true} :int]
[:bar {:optional true} :int]]
[Exclusive #{:hah :bar}]
[Exclusive #{:hah :foo}]]
(m/explain {:foo 1 :hah 2})
(me/humanize))
; => #:malli{:error ["the following keys are mutually exclusive: :hah, :foo"]}