-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Can we subclass clojure.lang.MultiFn? #34
Comments
If I'm understanding correctly, the goal of this is to allow users to use advanced methodical techniques even on multimethods defined upstream in library code out of their control? So for example: (ns my.project
(require
[methodical.core :as m]
[some.upstream.lib :as lib]))
(m/defmethod lib/vanilla-multimethod :before :default [x]
(do-stuff x)) Because that would be truly awesome. Maybe I'm just missing something, but is it possible to accomplish this by delegating to (defprotocol MethodicalMultiFn
(add-primary-method! [multifn-var dispatch-val f])
...)
(extend-protocol MethodicalMultiFn
clojure.lang.MultiFn
(add-primary-method! [multifn-var dispatch-val f]
(.addMethod (deref multifn-var) dispatch-val f))
...
StandardMultiFn
(add-primary-method! [multifn-var dispatch-val f]
...standard impl...)) I only just started looking at this and don't really understand how auxiliary methods are implemented yet, but in theory as long as your |
@acobster I'm not sure we'd be able to support aux methods on vanilla multimethods. I was thinking more that we'd let you use I think this should be possible, because |
For ClojureScript, there's an For JVM Clojure there's no protocol, so we'd have to subclass |
|
So the usual functions like
clojure.core/defmethod
and the like can be used. This will make Methodical a true drop-in replacement.Need to figure out how this will work since
clojure.lang.MultiFn
is a mutable object and.addMethod
actually changes its state, while Methodical multimethods are immutable, so you can only add methods and the like withalter-var-root
or equivalent.Not sure it would actually be possible without reworking Methodical multimethods so they are mutable objects
The text was updated successfully, but these errors were encountered: