Skip to content

Instantly share code, notes, and snippets.

@qerub
Created July 1, 2013 15:27
Show Gist options
  • Save qerub/5901842 to your computer and use it in GitHub Desktop.
Save qerub/5901842 to your computer and use it in GitHub Desktop.
Clojure functions for Java enum ordinals
(defn enum-ordinal [^Enum x]
(.ordinal x))
(defn enum-cmp [cmp & xs]
(apply cmp (map enum-ordinal xs)))
(defmacro defenumop [cmp]
`(def ~(symbol (str "enum" cmp))
(partial enum-cmp ~cmp)))
(defenumop =)
(defenumop >)
(defenumop <)
(defenumop >=)
(defenumop <=)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment