[Newbies] Does Set respect ordering?
gettimothy at zoho.com
Tue Feb 11 18:05:07 UTC 2020
The implementation of withoutDuplicates is brilliant.
"Answer a copy of the receiver that preserves order but eliminates any
| 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