[squeak-dev] The Trunk: Collections-eem.756.mcz
Levente Uzonyi
leves at caesar.elte.hu
Fri Jun 16 12:16:12 UTC 2017
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)"
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]]!
>
>
>
More information about the Squeak-dev
mailing list
|