[Newbies] Does Set respect ordering?
tty
gettimothy at zoho.com
Tue Feb 11 18:05:07 UTC 2020
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
More information about the Beginners
mailing list