The case
doc says
Unlike cond and condp, case does a constant-time dispatch... All manner of constant expressions are acceptable in case.
I would like to benefit from case
's constant-time dispatch to match on Java enums. Java's switch
statement works well with enums, but doing the following in Clojure:
(defn foo [x]
(case x
java.util.concurrent.TimeUnit/MILLISECONDS "yes!"))
(foo java.util.concurrent.TimeUnit/MILLISECONDS)
Results in: IllegalArgumentException No matching clause: MILLISECONDS
Are enums not supported in case
? Am I doing something wrong? Must I resort to cond
or is there a better solution?