Skip to content

Commit 4b853af

Browse files
committed
method
1 parent 9e111a1 commit 4b853af

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/darkleaf/multidecorators.cljc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
(into (pop queue) tag-parents)))
2020
(distinct acc))))
2121

22+
(defn- method [registry tag initial]
23+
(let [tags (reversed-me-and-ancestors tag)]
24+
(->> tags
25+
(map registry)
26+
(remove nil?)
27+
(reduce (fn [acc decorator]
28+
(fn [obj & args]
29+
(apply decorator acc obj args)))
30+
initial))))
31+
2232
(defn multi [dispatch initial]
2333
(let [iregistry (atom {})]
2434
(fn
@@ -28,15 +38,7 @@
2838
:initial initial})
2939
([obj & args]
3040
(let [tag (apply dispatch obj args)
31-
tags (reversed-me-and-ancestors tag)
32-
reg @iregistry
33-
f (reduce (fn [acc tag]
34-
(if-some [decorator (reg tag)]
35-
(fn [obj & args]
36-
(apply decorator acc obj args))
37-
acc))
38-
initial
39-
tags)]
41+
f (method @iregistry tag initial)]
4042
(apply f obj args))))))
4143

4244
(defn ^{:style/indent :defn} decorate [multi tag decorator]

0 commit comments

Comments
 (0)