Question

I need an implementation of the case macro. The original clojure implementation can't be used since it is kind of using the Java case statement internally.

http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/case

case macro

Usage: (case e & clauses)

I could try to build a macro on my own but it would be all clojure. Maybe there is even a way to use real js functionality.

Has anyone a function or macro for that?

Was it helpful?

Solution

UPDATE: case has since been added to ClojureScript. Though we cannot give the performance guarantees, the benefits for portability are more important.

case involves a guarantee that's not possible in JavaScript - constant time dispatch on literals. Is there any reason the following doesn't work for you?

(condp = x
   ...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top