malli

2024-11-14T20:20:38.557769Z

I'm a bit confused by malli.core/unparse. I'm finding that literal data equal to the result of malli.core/parse cannot be unparsed. Is that intentional?

(def int-or-string [:orn [:int :int] [:str :string]])

(malli.core/parse int-or-string 1) ;; -> [:int 1]

(malli.core/unparse int-or-string [:int 1]) ;=> :malli.core/invalid

(->> 1
     (malli.core/parse int-or-string)
     (malli.core/unparse int-or-string)) ;; => 1

opqdonut 2024-11-18T09:13:29.586699Z

unfortunately that's not a vector, it's a malli tagged value

opqdonut 2024-11-18T09:13:47.013889Z

(malli.core/unparse int-or-string (malli.impl.util/-tagged :int 1))
;; => 1

opqdonut 2024-11-18T09:14:34.198469Z

oh, it's actually not a tagged value, it's a MapEntry!

opqdonut 2024-11-18T09:14:51.154429Z

(class (malli.core/parse int-or-string 1))
;; => clojure.lang.MapEntry

opqdonut 2024-11-18T09:15:03.763019Z

regardless, I think vectors of size 2 should work. could you submit an issue?

👍 1
opqdonut 2024-11-18T09:15:55.883189Z

ah, -tagged just returns a MapEntry

opqdonut 2024-11-18T09:17:04.695919Z

the impl of the orn unparser expects a -tagged https://github.com/metosin/malli/blob/0680cdde7ac476e0dc2350ff6dc0bed3b5f4b50f/src/malli/core.cljc#L874