[Newbies] unique items in a collection
David T. Lewis
lewis at mail.msen.com
Fri Feb 15 11:42:25 UTC 2008
On Fri, Feb 15, 2008 at 11:21:42AM +0000, Frank Urbach wrote:
> Dear list,
> sometimes I get a collection with many items in it and want to get a collection where the occurrencesOf: each item should 1.
> So I'm searching for an selector like 'unique'.
> Is there a such a thing?
Yes, a Set is what you want. In most cases you can simply do this:
If you want to look at your set in an inspector, you may find it
convenient to turn it back into an array, which is much easier to
myCollection asSet asArray inspect
I recommend taking some time to look through the classes and methods
in the Collection hierarchy. There are lots of useful things hidden
there, and once you get comfortable working with them, it's just
like having a database at your fingertips, right in Squeak.
More information about the Beginners