[squeak-dev] The Trunk: Collections-eem.756.mcz
Nicolai Hess
nicolaihess at gmail.com
Fri Jun 16 12:18:49 UTC 2017
2017-06-16 14:16 GMT+02:00 Levente Uzonyi <leves at caesar.elte.hu>:
> On Fri, 16 Jun 2017, Nicolai Hess wrote:
>
> Does this even work ?
>> Set does not preserve ordering.
>>
>
> The receiver is not a Set but a SequenceableCollection, so yes, it does
> work:
>
> | set |
> set := Set new.
> #(1 1 2 1 2 3 1 2 3 4) select: [ :each | set addNewElement: each ]
>
> "==> #(1 2 3 4)"
>
Ah, of course :)
Set is only used for the select.
>
> Levente
>
>
>
>> Item was added:
>> + ----- Method: SequenceableCollection>>withoutDuplicates (in category
>> 'copying') -----
>> + withoutDuplicates
>> + "Answer a copy of the receiver that preserves order but
>> eliminates any duplicates."
>> + | seen |
>> + seen := Set new: self size.
>> + ^self select: [:each|
>> + (seen includes: each)
>> + ifTrue: [false]
>> + ifFalse: [seen add: each. true]]!
>>
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170616/157133a9/attachment.html>
More information about the Squeak-dev
mailing list
|