Fork me on GitHub
#clojuredesign-podcast
<
2020-10-23
>
nate19:10:30

In today's episode, we talk about multimethods: https://clojuredesign.club/episode/087-polymorphic-metal/

3
👂 3
bartuka01:11:29

Nice episode. @U0510902N you mentioned about using (def my-interface nil) to not loose your repl session and keep your defmulti in sync... there is also another trick that I use to do the same.. I find it a little bit easier (maybe bc I'm used to it)

(defn dispatch-fn [m]
  (:nice-logic m))

(defmulti my-interface #'dispatch-fn)
if you re-eval the definition of dispatch-fn there is no need to re-eval the defmulti, everything is synced! 😃

nate01:11:45

That's a great tip. I'll have to try that next time to prevent wedges related to the dispatch. It's a nice way of controlling the dispatch function outside of the multi. Also, having it as a top level fn makes it easier to print the dispatched return value for debugging.

bartuka02:11:38

Exactly! I work processing several files where 70% of their content is the same, but 30% is wildly different. I pray for multimethod everyday! haha. Another tip would be the usage of https://github.com/aleph-io/potemkin import-vars to combine definitions and implementations in the same namespace. (when you need to have them separate for ny reason) Let says we have interfaces.clj and impl1.clj, impl2.clj , etc.. now you have several files to remember requiring when you want to use a specific interface+implementation.. you can glue them together in a feature.clj namespace using import-vars. Now, you are sure that the interface and the implementations are both required and you only need to look into feature.clj

nate02:11:12

Interesting. I've only heard of potemkin, haven't needed it so far.