Here is what I came up with.
(let [d [#{#{1 2} #{3 4}} #{#{5 6} #{7 8}}]]
(reduce
(fn [mp nd]
(apply merge
(for [nd-pair nd face nd-pair] (update-in mp [face] #(conj
% nd))))) {} d))
On Dec 3, 3:42 am, Sunil S Nandihalli <[email protected]>
wrote:
> 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 [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