Sets are good when you have a collection of things, the precise order isn't
important to you, and you want to avoid duplicates. I used one in some code
recently where I wanted to maintain a collection of people who were co-authors
in a Clojure patch, and the input file I started with could mention the same
person's name multiple times. I only wanted each person to be included once,
no matter how many times they were mentioned in the patch file, and I didn't
care about the order they appeared.
Sets are also a nice way to take another Clojure collection and eliminate
duplicates -- just call (set coll) on the collection or sequence.
I haven't used them before, but if you want to avoid duplicates, and care about
the order, sorted-set can be useful in some situations.
Andy
On Mar 23, 2012, at 7:47 AM, Leandro Oliveira wrote:
> Thank you for all replies.
>
> The reason that I was using set instead of map was to use the functions from
> closure.set. I like them.
>
> But now I agree that map is a better approach.
>
> (select (fn [{:keys [id]}] (not= id 1)) xrel) is O(n). Right?
>
> Can I say that if you need remove an item you should use a map?
>
> What sets are good for?
>
> leandro.
--
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