This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-22
Channels
- # announcements (9)
- # asami (52)
- # aws (1)
- # babashka (7)
- # babashka-sci-dev (12)
- # beginners (72)
- # calva (24)
- # cider (9)
- # clj-kondo (76)
- # cljs-dev (15)
- # clojure (19)
- # clojure-australia (4)
- # clojure-europe (33)
- # clojure-france (9)
- # clojure-gamedev (17)
- # clojure-nl (6)
- # clojure-portugal (5)
- # clojure-uk (5)
- # clojurescript (61)
- # clojureverse-ops (4)
- # code-reviews (23)
- # conjure (1)
- # data-science (2)
- # datalevin (6)
- # datomic (49)
- # gratitude (1)
- # helix (24)
- # holy-lambda (14)
- # jobs (3)
- # lsp (92)
- # malli (7)
- # missionary (8)
- # pathom (12)
- # proletarian (3)
- # re-frame (4)
- # remote-jobs (1)
- # shadow-cljs (4)
- # spacemacs (3)
- # sql (9)
- # tools-build (90)
- # vim (1)
- # xtdb (11)
@hello525 sure, you could
1. put a transformer into top-level schema using schema properties as do update-in
to the value
2. m/walk
the schema and add the paths as schema properties to each schema. With this + :compile
in transformer, you can select the schemas that need to changed at transformer creation time. There is malli.util.subschemas
which could be looked as example imp how to find paths for each (nested) schema element
Is there a function like validate
that will throw instead of returning a value?
at the moment, no. If that would he added, there would be a reason to add throwing validator
, explain
, explainer
, parse
, parser
, transform
, transformer
too
Cool, it’s fine really, just wanted to check 🙂
However you can create such function yourself 😄
Something like:
(defn- explain!
[aschema x fn-name]
(when-let [info (m/explain aschema x)]
(when (or cfg/BROWSER? cfg/TEST_ENV?)
(throw (ex-info "[Malli] Schema does not match the argument"
{:type :malli-error
:x (form->pprint-str x 3)
:fn-name fn-name
:info (form->pprint-str (me/humanize info) 3)
:schema-name (schema-name aschema)
:schema-doc (schema-doc aschema)
:schema (schema->form-pprint-str (schema-form aschema))})))))
some perf numbers 0.6.1 vs 0.7.0 (unreleased):
(def ?schema
[:map
[:x boolean?]
[:y {:optional true} int?]
[:z [:map
[:x boolean?]
[:y {:optional true} int?]]]])
;; 44µs -> 2.9µs (15x)
(p/bench (m/schema ?schema))
;; 240ns (180x, parses entries when actually needed)
(p/bench (m/schema ?schema {::m/lazy-entries true}))
(def schema (m/schema ?schema))
;; 1.7µs -> 64ns (25x)
(p/bench (m/validate schema {:x true, :z {:x true}}))