Re: Does Set respect ordering?
Posted by
tty on
Feb 11, 2020; 6:05pm
URL: https://forum.world.st/Does-Set-respect-ordering-tp5111536p5111549.html
The implementation of withoutDuplicates is brilliant.
*withoutDuplicates
"Answer a copy of the receiver that preserves order but eliminates any
duplicates."
| seen |
seen := Set new: self size.
^self select: [:each| seen ifAbsentAdd: each]*
The Set acts as a growing "mask" of what is allowed in the OrderedCollection
returned by select.
I have never seen this idiom. Truly inspiring.
--
Sent from:
http://forum.world.st/Squeak-Beginners-f107673.html_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners