This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-23
Channels
- # announcements (1)
- # architecture (20)
- # babashka (30)
- # beginners (79)
- # calva (27)
- # cider (8)
- # clj-kondo (1)
- # clojure (125)
- # clojure-australia (1)
- # clojure-berlin (4)
- # clojure-europe (62)
- # clojure-france (1)
- # clojure-italy (6)
- # clojure-nl (4)
- # clojure-uk (12)
- # clojuredesign-podcast (5)
- # clojurescript (28)
- # core-async (31)
- # cursive (14)
- # datomic (47)
- # defnpodcast (1)
- # emacs (7)
- # figwheel-main (2)
- # fulcro (10)
- # graalvm (1)
- # graphql (11)
- # jobs-discuss (8)
- # leiningen (2)
- # off-topic (23)
- # rdf (9)
- # re-frame (3)
- # reagent (1)
- # reitit (5)
- # reveal (12)
- # shadow-cljs (12)
- # spacemacs (1)
- # tools-deps (87)
- # vim (22)
- # xtdb (21)
In today's episode, we talk about multimethods: https://clojuredesign.club/episode/087-polymorphic-metal/
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! 😃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.
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