Created
March 3, 2015 21:21
-
-
Save bts/bda3547ceb51f06d808a to your computer and use it in GitHub Desktop.
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 topo-sort | |
"Provided a map of values to their dependencies, returns a seq of the values | |
sorted topologically. | |
Adapted from code by cgrande at: | |
https://groups.google.com/forum/#!topic/clojure/-sypb2Djhio" | |
[deps] | |
(mapcat #(for [[u vs] % | |
:when (empty? vs)] | |
u) | |
(take-while seq | |
(iterate (fn [deps] | |
(into {} | |
(for [[u vs] deps | |
:when (seq vs)] | |
[u (mapcat deps vs)]))) | |
deps)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment