Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require '[com.stuartsierra.dependency :as dep])
- (-> (dep/graph)
- (dep/depend :b :a) ; "B depends on A"
- (dep/depend :c :b) ; "C depends on B"
- (dep/depend :c :a) ; "C depends on A"
- (dep/depend :d :c)
- (dep/topo-sort))
- ; Some new edges we want to add the the graph.
- (def new-edges [[:b :a] [:c :b] [:c :a] [:d :c]])
- ; dep/depend is cumbersome when you have edge tuples.
- (defn add-edge [g e]
- (apply dep/depend g e))
- ; Add and get topological sorting.
- (dep/topo-sort (reduce add-edge (dep/graph) new-edges))
- ; Rewrite to threading again.
- ; Note that the (#(...)) trick doesn't play well with
- ; functions like reduce, map, etc when the function they
- ; take is written using #(...).
- (-> (dep/graph)
- (#(reduce add-edge % new-edges))
- dep/topo-sort)
- ; Use reduce' instead.
- (defn reduce' [x f ys]
- (reduce f x ys))
- ; Works well with ->.
- (-> (dep/graph)
- (reduce' add-edge new-edges)
- (dep/topo-sort))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement