vendredi 4 février 2022

Clojure: override a method on a reified type

I would like to override a method on a reified type, but preserve all other methods. What is the simplest way to do that? For example:

I have:

(deftype Adapter []
 some.namespace/SomeProtocol
 (type-name-get [this] (:Adapter))
 ...)
(def adapter-instance (Adapter.))

And I want to get:

(def modified-adapter-instance
 (some-magic-fn adapter-instance type-name-get (fn [this] :ModifiedAdapter)))
(.type-name-get adapter-instance) => :Adapter
(.type-name-get modified-adapter-instance) => :ModifiedAdapter




Aucun commentaire:

Enregistrer un commentaire