Skip to content

Instantly share code, notes, and snippets.

@vermiculus
Last active May 1, 2016
Embed
What would you like to do?
(defn get-topic-children [topics topic-id]
(map first (filter #(= topic-id (:parent (second %))) topics)))
(defn get-routes [topics topic-id & [slug-so-far]]
(let [children (get-topic-children topics topic-id)
newslug (if (= topic-id :root) ""
(str slug-so-far "/" (:slug (get topics topic-id))))]
(if children
(into (if (= topic-id :root) {} {topic-id newslug})
(map #(get-routes topics % newslug) children))
{topic-id newslug})))
(let [topics {1 {:parent :root, :slug "lovely"}
2 {:parent 1, :slug "lovelier"}
3 {:parent 1, :slug "loveliest"}
4 {:parent :root, :slug "cool"}}
(get-routes topics :root))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment