I have a case where I want several dispatch values in a multimethod to map to the same method. For example, for a dispatch value of 1 I want it to call method-a, and for dispatch values of 2, 3, or 4 I want it to call method-b.
After some Googling, I ended up writing the following macro:
(defmacro defmethod-dispatch-seq [mult-fn dispatch-values & body] `(do (map (fn [x#] (defmethod ~mult-fn x# ~@body)) ~dispatch-values))) You can then use it like this:
(defmulti f identity) (defmethod f 1 [x] (method-a x)) (defmethod-dispatch-seq f [2 3 4] [x] (method-b x)) Which allow you you to call the following:
(f 1) => (method-a 1) (f 2) => (method-b 2) (f 3) => (method-b 3) (f 4) => (method-b 4) Is this a good idea?