Hello, one way:
(apply merge-with conj {} (for [nd d nd-pair nd face nd-pair] {face nd})) The idea is (as is generally the case for me when trying to move from imperative code to functional), is to try not to do too many things in a single step. So here, first I extract from the "for" "pieces of information", individual pairs of face => containing-node into an intermediate sequence. Then I consume this sequence with merge-with. I could also consume this sequence with reduce, of course: (reduce (fn [m fnd] (merge-with conj m fnd) (for ...)) HTH, -- Laurent 2010/12/3 Sunil S Nandihalli <sunil.nandiha...@gmail.com> > Hello everybody, > > I would like to know as to how I would write the following code in a more > idiomatic way. > > > > > > (let [mp (atom {}) > > > d [#{#{1 2} > > > #{3 4}} ;node1 > > > #{#{5 6} > > > #{7 8}} ;node2]] > > > (dorun (for [nd d nd-pair nd face nd-pair] > > > (swap! mp update-in [face] #(conj % nd)))) > > > @mp) > > > > > ; if you consider that points 1 2 3 4 form the node node1 and 5 6 7 8 form > node2 > > > ;I would like a map in the opposite direction .. > > > ;i.e. I should be able to find out all the nodes of which 1 is part of and > > > ;that is what the above code is doing.. but would like to know as to what > > > ;would be a more idiomatic way of doing this. > > > > > > https://gist.github.com/726773 > > > > > I don't like the fact that I am using atom and swap .. can anybody suggest a > better way to do it? > > > > Thanks, > Sunil. > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en