From 3d4737b3fbbaad361045c5a10476670b1908c845 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Mon, 7 Aug 2017 14:23:16 +0300 Subject: [PATCH] Cleanup code --- src/reitit/core.cljc | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/reitit/core.cljc b/src/reitit/core.cljc index 681d22ba..1c8b879b 100644 --- a/src/reitit/core.cljc +++ b/src/reitit/core.cljc @@ -38,18 +38,14 @@ ([routes] (walk ["" []] routes)) ([[pacc macc] routes] - (let [subwalk (fn [path meta routes] - (reduce - (fn [acc route] - (into acc (walk [path meta] route))) - [] - routes))] + (letfn [(subwalk [p m r] + (reduce #(into %1 (walk [p m] %2)) [] r))] (if (vector? (first routes)) (subwalk pacc macc routes) (let [[path & [maybe-meta :as args]] routes] - (let [[meta childs] (if-not (vector? maybe-meta) - [maybe-meta (rest args)] - [{} args]) + (let [[meta childs] (if (vector? maybe-meta) + [{} args] + [maybe-meta (rest args)]) macc (into macc (expand meta))] (if (seq childs) (subwalk (str pacc path) macc childs) @@ -58,16 +54,13 @@ (defn map-meta [f routes] (mapv #(update % 1 f) routes)) -(defn merge-meta - ([x] - (merge-meta (constantly :into) x)) - ([key-strategy x] - (reduce - (fn [acc [k v]] - (let [strategy (or (key-strategy k) :replace)] - (deep-merge strategy acc {k v}))) - {} - x))) +(defn merge-meta [key-strategy x] + (reduce + (fn [acc [k v]] + (let [strategy (or (key-strategy k) :replace)] + (deep-merge strategy acc {k v}))) + {} + x)) (defn resolve-routes ([x]