Fork me on GitHub
#malli
<
2022-10-31
>
dumrat09:10:44

(me/humanize
  (m/explain
    [:and
      [:fn (fn [{:keys [tag]}] (= :Portfolio tag))]
      ...]
    {:tag :some-other-tag ...}))
=>
["unknown error"]
I understand that the "unknown error" is the result because malli doesn't know what to say when my custom function returns false. Can I customize this error message here?

dumrat09:10:50

I know I can use :enum here to do the same validation. Just want to know how to handle custom fns.

ikitommi09:10:39

(me/humanize
 (m/explain
  [:and
   [:fn {:error/message "horror"}
    (fn [{:keys [tag]}] (= :Portfolio tag))]]
  {:tag :some-other-tag}))
; => ["horror"]

👍 1
dumrat09:10:37

great thanks

ikitommi09:10:44

you’re welcome

dumrat15:10:57

Data:

[{:key1 1 :val 4} {:key2 2 :val 5} {:key3 3 :val 6}]
I'd like to write a schema which requires all three keys key1, key2, key3 to be present in the sub maps of the input vector. How to do this?