Here are a few reasons.
A) Vanilla multimethods in Clojure either dispatch to a specific method or :default
but there's no in-between. You can't do something like
(defmulti describe-animal-location (fn [animal location] (keyword animal) (keyword location)))
(defmethod describe-animal-location [:bird :tree]
[_ _]
"Bird in a tree")
;; can't do this
(defmethod describe-animal-location [:default :tree]
[animal _]
(str animal " in a tree"))
B) Aspect-oriented programming. Write a single logging method for all your implementations.
(m/defmethod describe-animal-location :before :default
[animal location]
(println "describe-animal-location called with" animal location)
location)
C) next-method
.
In Clojure if you want call the "parent" method, you'd have to do something like
(defmethod describe-animal-location [:songbird :tree]
[animal location]
(println "A songbird is in a tree.")
((get-method describe-animal-location :bird :tree) animal location))
That requires you to know what the "parent method" is. In Methodical you can simply do
(m/defmethod describe-animal-location [:songbird :tree]
[animal location]
(println "A songbird is in a tree.")
(next-method animal location))
D) Programmatic multimethod creation.
Normal multimethods can't be passed around and modified on-the-fly like normal functions or other Clojure datatypes -- they're defined statically by `defmulti`, and methods can only be added destructively, by altering the original object. Methodical multimethods are implemented entirely as immutable Clojure objects (with the exception of caching).
(let [dispatch-fn :type
multifn (-> (m/default-multifn dispatch-fn)
(m/add-primary-method Object (fn [next-method m]
:object)))
multifn' (m/add-primary-method multifn String (fn [next-method m]
:string))]
((juxt multifn multifn') {:type String}))
;; -> [:object :string]
E) Custom invocation behavior: you can write a multimethod that invokes all its implementations -- the canonical use-case for this is creating a shutdown hook.
F) Debuggability: You can use tools that ship with Methodical like trace
to see what methods are getting called and trace calls to a multimethodHey guys, I just released the 0.1.0 version of https://github.com/lucywang000/clj-statecharts, the finite state machine and statecharts library for clojure/clojurescript. This is the first formal release. I have being using it for a while in several internal applications, and it works pretty well insofar.
7👍25🎉We proudly present our new Keycloak Convention4Kubernetes deployment generator: https://gitlab.com/domaindrivenarchitecture/c4k-keycloak We provide the generator as jvm-library, js-webfrontend and standalone cli. https://social.meissa-gmbh.de/tags/keycloak https://social.meissa-gmbh.de/tags/k8s https://social.meissa-gmbh.de/tags/c4k https://social.meissa-gmbh.de/tags/clojure https://social.meissa-gmbh.de/tags/clojurescript https://social.meissa-gmbh.de/tags/graalvm
3👍Thank you!
1👍