In Clojure, what is the idiomatic way to validate that a value is one of a set of possible values?
I initially did something like this:
(let [size :grande]
(make-latte (condp = size
:tall :tall
:grande :grande)))
The above is useful because if no clause matches an IllegalArgumentException
is thrown.
But then I found this more comfortable to do:
(let [size :grande]
(make-latte (or (some #{:tall :grande} [size])
(throw (IllegalArgumentException. "I don't know that size")))
This technique works well because it allows for more possible values, e.g.
(some #{:short :tall :grande :venti} [size])
What's the best way to do this? Am I right in thinking that clojure.core
does not have a function that does this already?