collectionssmalltalkpharosqueak

unique or distinct for collections in squeak(Smalltalk)


there is a method like uniq in bash for collections in squeak?

to remove all duplications in the collection and get a collection with one of each distinct obj.

For example:

before: #('cat', 'cat', 'dog', 'cat')

after: (uniq) #('cat', 'dog')


Solution

  • There exist quite a few ways of doing the same in subtly different ways, depending on your needs. The more popular ones I can think of are: