metosin / malli

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

infer :enum and := transformers from int? or keyword? values #782

Closed ikitommi closed 1 year ago

ikitommi commented 1 year ago

Similar to Plumatic solution.

;; uniform :enum type
(m/decode [:enum :A :B :C] "A" (mt/string-transformer))
; => :A

;; non-uniform :enum type
(m/decoder [:map [:x [:enum :A :B "C"]]] (mt/string-transformer))
; => #object[clojure.core$identity]
ikitommi commented 1 year ago

note - this is not a full solution to the problem. see https://github.com/metosin/malli/issues/264

Deraen commented 1 year ago

Makes sense.

What about other "simple" types in json/string-decoders that might be used? Symbols, uuid, double, float?

ikitommi commented 1 year ago

added support for symbol, double and float (double via float)). I think this is good enough now, as said, we should have a -value-type definition ("what type of values does this accept") separate of -type ("name of the schema") as this applies to many applications like: