Here's another way, which constructs a sequence of edges using candidates,
which are then fed into reduce to build an adjacency list.
(defn candidates->edges [candidates from to]
(when-let [kids (seq (candidates from to))]
(concat (for [k kids] [from k])
(mapcat #(get-edges candidates % to) kids))))
(defn edges->adj [edges]
(reduce
(fn [adj [a b]]
(update-in adj [a] conj b))
{} edges))
(edges->adj (candidates->edges candidates :a :e))
; => {:d (:e), :c (:e), :b (:d :c), :a (:b)}
This doesn't handle cycles.
Justin
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en