Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #33: Add >defmethod #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/ghostwheel/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,22 @@
(cljs-env? &env) clj->cljs)
(clean-defn 'defn- forms)))

(defmacro >defmethod
"Like defmethod, but requires a (nilable) gspec definition and generates
additional `s/fdef`, generative tests, instrumentation code, an
fspec-based stub, and/or tracing code, depending on the configuration
metadata and the existence of a valid gspec and non-nil body."
[multifn dispatch-val argv gspec & body]
(let [delegate-defn-name (symbol (str multifn "_" (gensym)))]
`(do
(>defn ~delegate-defn-name
~argv
~gspec
~@body)
(defmethod ~multifn
~dispatch-val
~argv
(~delegate-defn-name ~@argv)))))

(defmacro after-check
"Takes a number of 0-arity functions to run
Expand Down