Skip to content

Instantly share code, notes, and snippets.

@bts
Created March 3, 2015 21:21
Show Gist options
  • Save bts/bda3547ceb51f06d808a to your computer and use it in GitHub Desktop.
Save bts/bda3547ceb51f06d808a to your computer and use it in GitHub Desktop.

Revisions

  1. bts revised this gist Mar 3, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions topo-sort.clj
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    (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"
    "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)]
  2. bts created this gist Mar 3, 2015.
    16 changes: 16 additions & 0 deletions topo-sort.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    (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))))