Last active
May 1, 2016 22:42
-
-
Save vermiculus/c8a531a86a0a65cdb9af4a466ed0721f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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