https://github.com/darkleaf/multidecorators
Like multimethods but multidecorators.
https://github.com/darkleaf/multidecorators
aop aspect-oriented-programming clojure clojurescript decorator-pattern inheritance middlware multimethods
Last synced: about 1 month ago
JSON representation
Like multimethods but multidecorators.
- Host: GitHub
- URL: https://github.com/darkleaf/multidecorators
- Owner: darkleaf
- License: unlicense
- Created: 2019-06-28T18:36:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-19T18:58:43.000Z (over 5 years ago)
- Last Synced: 2025-03-27T23:51:06.281Z (2 months ago)
- Topics: aop, aspect-oriented-programming, clojure, clojurescript, decorator-pattern, inheritance, middlware, multimethods
- Language: Clojure
- Homepage:
- Size: 11.7 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://clojars.org/darkleaf/multidecorators)
# Multidecorators
Like multimethods but multidecorators.
+ clojure(script)
+ dead simple
+ no deps
+ no macros## Usage
```clojure
(ns example
(:require
[darkleaf.multidecorators :as md]));; diamond inheritance
(derive ::d ::b)
(derive ::d ::c)
(derive ::b ::a)
(derive ::c ::a)(defn dispatch [obj]
obj)(defn initial [obj]
[])(defonce func (md/multi #'dispatch #'initial))
(md/decorate func ::a
(fn a-decorator [super obj]
(conj (super obj) :a)))(md/decorate func ::b
(fn b-decorator [super obj]
(conj (super obj) :b)))(md/decorate func ::c
(fn c-decorator [super obj]
(conj (super obj) :c)))(md/decorate func ::d
(fn d-decorator [super obj]
(conj (super obj) :d)))(md/decorate func ::e
(fn e-decorator [super obj]
(conj (super obj) :e)))(assert (= [:a] (func ::a)))
(assert (= [:a :b] (func ::b)))
(assert (= [:a :c] (func ::c)))
(assert (= [:a :b :c :d] (func ::d)))
(assert (= [:e] (func ::e)))
(assert (= [] (func ::f)))
```## Development
```
lein test
lein doo node node-none once
lein doo node node-advanced once
```