Created
June 14, 2012 21:05
-
-
Save mattmoss/2932951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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