-
-
Save ninjudd/606679 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
;; wouldn't it be nice if... | |
(def-type-multis DataRow | |
(get-column-names [this]) | |
(get-value [this column-name])) | |
(defmethods DataRow | |
clojure.lang.Associative | |
(get-column-names [this] | |
(range (count this))) | |
(get-value [this column-name] | |
(nth this column-name))) | |
;; so make it happen... | |
(defn type* [obj & _] (type obj)) | |
(defmacro def-type-multis [name & methods] | |
`(do | |
~@(for [[method-name] methods] | |
`(defmulti ~method-name type*)))) | |
(defmacro defmethods [name dispatch-value & methods] | |
`(do | |
~@(for [[method-name & more] methods] | |
`(defmethod ~method-name ~dispatch-value ~more)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment