metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.5k stars 211 forks source link

README incorrect about enum transformation #788

Closed camdez closed 1 year ago

camdez commented 1 year ago

The README says:

Transforming homogenous :enum or :=s (supports automatic type detection of :keyword, :symbol, :int and :double):

(m/decode [:enum :kikka :kukka] "kukka" mt/string-transformer)
; => :kukka

But when I evaluate this locally (v0.9.2), I get:

(m/decode [:enum :kikka :kukka] "kukka" mt/string-transformer)
; => "kukka"

For anyone struggling with this, you can use :and to get the desired behavior:

(m/decode [:and keyword? [:enum :kikka :kukka]] "kukka" mt/string-transformer)
;; => :kukka
camdez commented 1 year ago

Actually, better to reverse the :and order if you're generating examples, otherwise it'll generate random keywords to test against the enumeration:

(m/decode [:and [:enum :kikka :kukka] keyword?] "kukka" mt/string-transformer)
;; => :kukka
camdez commented 1 year ago

Ahh, I see now that this is new and unreleased (#782, #784).

Closing.