Fork me on GitHub
#malli
<
2020-10-10
>
borkdude07:10:39

@ikitommi I'm reading through the Malli README and found a couple of spelling improvements: Homogenous -> Homogeneous

borkdude07:10:07

And this sentence: > You can also decomplected maps keys and values using registry references. seems to be grammatically a bit off

ikitommi08:10:25

@borkdude fixes are most welcome.

borkdude08:10:56

Just passing it here, do what you want with it :)

ikitommi08:10:08

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"]}

borkdude08:10:08

I was wondering, does malli also do the destructuring that spec does e.g. on a sequential regex schema? (s/cat etc)

borkdude08:10:27

or s/or, etc

borkdude08:10:01

someone should probably write a comparison/migration page for malli <-> spec :)

👍 3
ikitommi08:10:45

not yet, the internal api works, but not integrated into malli.core: https://github.com/metosin/malli/issues/180

borkdude08:10:01

exactly! thanks!

zilti18:10:51

When creating a validator, how do I use non-core functions in a :fn? Specifically, I want to use clojure.string/blank?

ikitommi19:10:42

@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.

ikitommi19:10:07

also, you can say [:string {:min 1}].

borkdude19:10:27

clojure.string/blank? works in sci by default

👍 6
zilti19:10:43

Oh, that :min seems to be the most straightforward for my usecase, I'll use that!