unique items in a collection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

unique items in a collection

Frank Urbach
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?

Cheers,
  Frank
Edelstahlwerke Schmees GmbH
Geschäftsleitung Clemens Schmees
Sitz D-01796 Pirna
Handelsregister Dresden HRB 54
E-Mail: [hidden email]
WEB:     www.schmees.com

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
 
This e-mail may contain confidental and/or privileged information. If you are not intended recipient or have received this e-mail in error, please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is stictly forbidden.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: unique items in a collection

David T. Lewis
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?

Frank,

Yes, a Set is what you want. In most cases you can simply do this:

        myCollection asSet

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
look at:

        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.

Dave

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners