mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
Rewrote reitit.core/path-conflicting-routes using transducers.
This commit is contained in:
parent
7ec5c79cad
commit
b77115850f
1 changed files with 10 additions and 10 deletions
|
|
@ -65,17 +65,17 @@
|
||||||
(cond->> (->> (walk raw-routes opts) (map-data merge-data))
|
(cond->> (->> (walk raw-routes opts) (map-data merge-data))
|
||||||
coerce (into [] (keep #(coerce % opts)))))
|
coerce (into [] (keep #(coerce % opts)))))
|
||||||
|
|
||||||
;; This whole function might be more efficient and easier to understand with transducers.
|
|
||||||
(defn path-conflicting-routes [routes]
|
(defn path-conflicting-routes [routes]
|
||||||
(some->>
|
(let [conflicting-routes
|
||||||
(loop [[r & rest] routes, acc {}]
|
(into {}
|
||||||
(if (seq rest)
|
(comp (map-indexed (fn [index route]
|
||||||
(let [conflicting (set (keep #(if (impl/conflicting-routes? r %) %) rest))]
|
[route (into #{}
|
||||||
(recur rest (update acc r (fnil (comp set concat) #{}) conflicting)))
|
(filter #(impl/conflicting-routes? route %))
|
||||||
acc))
|
(subvec routes (inc index)))]))
|
||||||
(filter (comp seq second))
|
(filter (comp seq second)))
|
||||||
(seq)
|
routes)]
|
||||||
(into {})))
|
(when (seq conflicting-routes)
|
||||||
|
conflicting-routes)))
|
||||||
|
|
||||||
(defn conflicting-paths [conflicts]
|
(defn conflicting-paths [conflicts]
|
||||||
(->> (for [[p pc] conflicts]
|
(->> (for [[p pc] conflicts]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue