From 4b853afa1eb5ee146fc66ba3a344354d1c3fc062 Mon Sep 17 00:00:00 2001 From: Mikhail Kuzmin Date: Wed, 19 Feb 2020 22:16:04 +0400 Subject: [PATCH] method --- src/darkleaf/multidecorators.cljc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/darkleaf/multidecorators.cljc b/src/darkleaf/multidecorators.cljc index a790430..427f83c 100644 --- a/src/darkleaf/multidecorators.cljc +++ b/src/darkleaf/multidecorators.cljc @@ -19,6 +19,16 @@ (into (pop queue) tag-parents))) (distinct acc)))) +(defn- method [registry tag initial] + (let [tags (reversed-me-and-ancestors tag)] + (->> tags + (map registry) + (remove nil?) + (reduce (fn [acc decorator] + (fn [obj & args] + (apply decorator acc obj args))) + initial)))) + (defn multi [dispatch initial] (let [iregistry (atom {})] (fn @@ -28,15 +38,7 @@ :initial initial}) ([obj & args] (let [tag (apply dispatch obj args) - tags (reversed-me-and-ancestors tag) - reg @iregistry - f (reduce (fn [acc tag] - (if-some [decorator (reg tag)] - (fn [obj & args] - (apply decorator acc obj args)) - acc)) - initial - tags)] + f (method @iregistry tag initial)] (apply f obj args)))))) (defn ^{:style/indent :defn} decorate [multi tag decorator]