@ikitommi I'm reading through the Malli README and found a couple of spelling improvements: Homogenous -> Homogeneous
And this sentence: > You can also decomplected maps keys and values using registry references. seems to be grammatically a bit off
@borkdude fixes are most welcome.
Just passing it here, do what you want with it :)
will fix
fixed
toyed with the declarative schema transformations, which might be useful when defining schemas in EDN:
(require '[malli.core :as m])
(require '[malli.util :as mu])
(require '[malli.error :as me])
(def registry (merge (m/default-schemas) (mu/schemas)))
(def XZ
(m/schema
[:select-keys
[:merge
[:map [:x int?]]
[:map [:y int?]]
[:map [:z int?]]]
[:x :z]]
{:registry registry}))
XZ
; [:select-keys
; [:merge
; [:map [:x int?]]
; [:map [:y int?]]
; [:map [:z int?]]]
; [:x :z]]
;; get the effective schema
(m/deref XZ)
; [:map [:x int?] [:z int?]]
;; internally uses the pre-computed effective schema
(-> XZ
(m/explain {:x 1})
(me/humanize))
; {:z ["missing required key"]}
I was wondering, does malli also do the destructuring that spec does e.g. on a sequential regex schema? (s/cat etc)
or s/or, etc
someone should probably write a comparison/migration page for malli <-> spec :)
not yet, the internal api works, but not integrated into malli.core: https://github.com/metosin/malli/issues/180
… and https://github.com/metosin/malli/issues/241 after that.
exactly! thanks!
When creating a validator, how do I use non-core functions in a :fn
? Specifically, I want to use clojure.string/blank?
@zilti :fn
takes any function as unquoted, so [:fn clojure.string/blank?]
. They don't serialize correctly, but work on the same runtime. If you use sci, you need to add custom bindings for the function for all runtimes. I believe str/blank?
is part of sci default bindings, so [:fn 'str/blank?]
should work too.
also, you can say [:string {:min 1}]
.
clojure.string/blank?
works in sci by default
Oh, that :min
seems to be the most straightforward for my usecase, I'll use that!
:string
has good default error messages: https://github.com/metosin/malli/blob/master/test/malli/error_test.cljc#L262-L283