Liking cljdoc? Tell your friends :D

Setup
API
Changelog
Usage
Alternatives
Contact

Extended `extend-protocol`

A Clojure macro to extend a protocol to multiple types with identical implementations

Setup

Leiningen/Boot

[com.sagevisuals/extended-extend-protocol "0"]

Clojure CLI/deps.edn

com.sagevisuals/extended-extend-protocol {:mvn/version "0"}

Require

(require '[extended-extend-protocol.core :refer [multi-extend-protocol]])

Usage

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 [argsbody), without an explicit fn.

Alternatives


License

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

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close