mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11: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))
|
||||
coerce (into [] (keep #(coerce % opts)))))
|
||||
|
||||
;; This whole function might be more efficient and easier to understand with transducers.
|
||||
(defn path-conflicting-routes [routes]
|
||||
(some->>
|
||||
(loop [[r & rest] routes, acc {}]
|
||||
(if (seq rest)
|
||||
(let [conflicting (set (keep #(if (impl/conflicting-routes? r %) %) rest))]
|
||||
(recur rest (update acc r (fnil (comp set concat) #{}) conflicting)))
|
||||
acc))
|
||||
(filter (comp seq second))
|
||||
(seq)
|
||||
(into {})))
|
||||
(-> (into {}
|
||||
(comp (map-indexed (fn [index route]
|
||||
[route (into #{}
|
||||
(filter #(impl/conflicting-routes? route %))
|
||||
(subvec routes (inc index)))]))
|
||||
(filter (comp seq second)))
|
||||
routes)
|
||||
(not-empty)))
|
||||
|
||||
(defn conflicting-paths [conflicts]
|
||||
(->> (for [[p pc] conflicts]
|
||||
|
|
|
|||
Loading…
Reference in a new issue