Fork me on GitHub
#malli
<
2023-02-10
>
Michael Gardner00:02:17

is there an established "best practice" re: calling m/schema or not in your schema defs? E.g.

(def foo-schema
  [:map ...])
vs
(def foo-schema
  (m/schema
   [:map ...]))
So far I've been writing the latter to get fail-fast behavior when a schema is invalid, but it's more verbose and forces the use of malli.util fns to transform/combine schemas. And AFAIK there's only a small performance benefit to calling m/schema thanks to Malli's caching. So I'm not sure what to pick as a default.

rutledgepaulv01:02:34

One suggestion could be to write a macro which defs and validates a schema but defines the value of the var as the original data as long as validation succeeds

rutledgepaulv01:02:11

Or a function that does the same and just use that instead of m/schema in your second example

Michael Gardner18:02:13

I could certainly do that, although it's still a little more verbose. And I'm not even sure I need it given that my data schemas will end up getting validated at ns load time via the function schemas that use them anyway. So I guess my only remaining question is about performance. Is it true that there's no meaningful performance benefit to calling m/schema any more?