Skip to content

Instantly share code, notes, and snippets.

@raek
Created May 29, 2011 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/997652 to your computer and use it in GitHub Desktop.
Save raek/997652 to your computer and use it in GitHub Desktop.
(defmacro class-case [expr & cases]
`(case (class ~expr)
~@(apply concat (for [case-row (partition-all 2 cases)]
(if (next case-row)
(if (seq? (first case-row))
[(map resolve (first case-row)) (second case-row)]
[(resolve (first case-row)) (second case-row)])
case-row)))))
; Usage
(class-case 123
Integer :int
Long :long
:something-else)
;=> :int
(class-case 123.0
(Long Integer Short Byte) :int-like
(Double Float) :float-like
:something-else)
;=> :float-like
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment