Given an enum made from prismatic schema.core/enum, let's say:
(def myenumtype (schema.core/enum "a" "b" "c"))
How can I set another def to a specific enum item? Here I would like to set e to the "a" enum item.
(def e (??? myenumtype))
And how can I compare this to a specific enum? Here I would like to check to see if e is equal to the "a" enum type.
(= e ((??? "a") myenumtype))
I think you're misunderstanding how Schema works. You're not creating an enum type, you're creating a validator that checks if a particular value equals one of the enumerated values.
In your case, all you need to do is:
(def e "a")
Here's an example REPL session:
user=> (schema.core/validate (schema.core/enum "a" "b" "c") "a")
"a"
=> (schema.core/validate (schema.core/enum "a" "b" "c") "z")
clojure.lang.ExceptionInfo: Value does not match schema: (not (#{"a" "b" "c"} "z"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With