This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn ways-by-node [ways] | |
(reduce | |
(partial merge-with (comp vec concat)) | |
(for [way ways, id (:nodes way)] | |
(hash-map id [(:id way)])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn collect-ways-by-node [ways] | |
(loop [ways ways | |
accum {}] | |
(if (seq ways) | |
(let [{:keys [nodes id]} (first ways) | |
new-accum (zipmap nodes (map vector (repeat id)))] | |
(recur (rest ways) (merge-with (comp vec concat) accum new-accum))) | |
accum))) |