[com.sagevisuals/extended-extend-protocol "0"]
com.sagevisuals/extended-extend-protocol {:mvn/version "0"}
(require '[extended-extend-protocol.core :refer [multi-extend-protocol]])
Clojure's extend-protocol doesn't provide a way to avoid repetitive implementations.
The singular macro of this library is one way avoid that repetition. Instead of repetitive type+implementation pairs,
multi-extend-protocol consumes a series of types sharing a common implementation, followed by the actual implementation.
Let's pretend we defined OurProtocol to consist of two methods, foo and bar. We supply a series of types
followed by the implementation.
(multi-extend-protocol OurProtocol
AType
BType
CClass
(foo [x] x)
(bar [y] y))
...expands to...
(extend-protocol OurProtocol
AType
(foo [x] x)
(bar [y] y)
BType
(foo [x] x)
(bar [y] y)
CClass
(foo [x] x)
(bar [y] y))
Investigate weirdness with macroexpand-1.
And note: multi-extend-protocol inherits extend-protocol's pattern of defining methods:
(function‑name [args] body), without an explicit fn.
Clojure's extend function and method maps.
This program and the accompanying materials are made available under the terms of the MIT License.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |