Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns scratch.scratch)
(def locations
[{:unit "moscow"
:type "city"
:subunits [{:unit "abc"
:type "area"}
{:unit "xyz"}]}
{:unit "london"}
{:unit "tokyo"}])
(reduce (fn [acc location]
(let [path [(:unit location)]]
(into (conj acc {:path path})
(reduce (fn [paths sublocation]
(conj paths {:path (conj path (:unit sublocation))}))
[]
(:subunits location)))))
[]
locations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment