[squeak-dev] The Trunk: Collections-eem.756.mcz
Tobias Pape
Das.Linux at gmx.de
Thu Jun 15 19:06:56 UTC 2017
> On 15.06.2017, at 20:30, Eliot Miranda <eliot.miranda at gmail.com> wrote:
>
> Hi Levente, Hi Chris,
>
> On Wed, Jun 14, 2017 at 1:10 PM, Levente Uzonyi <leves at caesar.elte.hu> wrote:
> On Wed, 14 Jun 2017, commits at source.squeak.org wrote:
>
> Eliot Miranda uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-eem.756.mcz
>
> ==================== Summary ====================
>
> Name: Collections-eem.756
> Author: eem
> Time: 14 June 2017, 11:03:24.917631 am
> UUID: 8d7c03bc-1cdb-44c7-9173-10d50c0dae29
> Ancestors: Collections-eem.755
>
> Add SequenceableCollection>>withoutDuplicates for a more elegant fix to MailMessage>>to:
>
> =============== Diff against Collections-eem.755 ===============
>
> 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]]!
>
> What a great opportunity to use #addNewElement::
>
> ^self select: [ :each | seen addNewElement: each ]
>
> I love the functionality but I don't like the selector. It seems to imply that one must only add a new element. So why not call this something like addIfAbsent: ?
>
> Here are some suggestions. Votes?
> - don't change it; stick with addNewElement:
> - addIfAbsent:
> - ifAbsentAdd:
> - ifMissingAdd:
>
> I think I prefer ifAbsentAdd: cuz addIfAbsent: looks too much like a potential spelling error, and conflicts with typical ifAbsent: arguments supplying exception blocks. But I could go with ifMissingAdd: because it is more distinctive.
Well, we do have
Collection>>addIfNotPresent:
So why invent a new one?
I think the important thing with #addNewElement: is that it returns *whether* it added a new element
but then again it breaks the tradition of #add* returning its argument…
a very clear and very strange one that would reveal that a boolean is returned would be #isAbsentAndIfSoAdd: …
Best regards
-Tobias
>
> _,,,^..^,,,_
> best, Eliot
More information about the Squeak-dev
mailing list
|