mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Merge pull request #208 from green-coder/master
Rewrote `reitit.core/path-conflicting-routes` using transducers
This commit is contained in:
commit
d30d1fdfaf
1 changed files with 8 additions and 10 deletions
|
|
@ -65,17 +65,15 @@
|
||||||
(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->>
|
(-> (into {}
|
||||||
(loop [[r & rest] routes, acc {}]
|
(comp (map-indexed (fn [index route]
|
||||||
(if (seq rest)
|
[route (into #{}
|
||||||
(let [conflicting (set (keep #(if (impl/conflicting-routes? r %) %) rest))]
|
(filter #(impl/conflicting-routes? route %))
|
||||||
(recur rest (update acc r (fnil (comp set concat) #{}) conflicting)))
|
(subvec routes (inc index)))]))
|
||||||
acc))
|
(filter (comp seq second)))
|
||||||
(filter (comp seq second))
|
routes)
|
||||||
(seq)
|
(not-empty)))
|
||||||
(into {})))
|
|
||||||
|
|
||||||
(defn conflicting-paths [conflicts]
|
(defn conflicting-paths [conflicts]
|
||||||
(->> (for [[p pc] conflicts]
|
(->> (for [[p pc] conflicts]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue