Skip to content

Instantly share code, notes, and snippets.

@mattmoss
Created June 14, 2012 21:05
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 mattmoss/2932951 to your computer and use it in GitHub Desktop.
Save mattmoss/2932951 to your computer and use it in GitHub Desktop.
(defn gen-id-dispatch
[& args]
(let [n (count args)]
(cond
(= n 1) (class (first args))
(= n 2) :pair
:else nil)))
(defmulti gen-id #'gen-id-dispatch :default nil)
(defmethod gen-id :pair
[x y]
{:a x :b y})
(defmethod gen-id String
[x]
{:a 0 :b x})
(defmethod gen-id nil [x] nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment