Fork me on GitHub

@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

馃憤 1

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鈥檚 fine really, just wanted to check 馃檪

Karol W贸jcik14:10:39

However you can create such function yourself 馃槃

Karol W贸jcik14:10:50

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
   [: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}}))

馃敟 8
馃弾锔 4