<div dir="ltr">maybe addOnce: would be more expressive than addNew:?<br><br><div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-15 22:52 GMT+02:00 Chris Muller <span dir="ltr"><<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">^ self select: [ : each | seen addNew: each ]<br>
<br>
?<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, Jun 15, 2017 at 3:50 PM, Chris Cunningham<br>
<<a href="mailto:cunningham.cb@gmail.com">cunningham.cb@gmail.com</a>> wrote:<br>
><br>
><br>
> On Thu, Jun 15, 2017 at 1:22 PM, Tobias Pape <<a href="mailto:Das.Linux@gmx.de">Das.Linux@gmx.de</a>> wrote:<br>
>><br>
>><br>
>> > On 15.06.2017, at 21:40, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br>
>> ><br>
>> > Hi Tobias,<br>
>> ><br>
>> > On Thu, Jun 15, 2017 at 12:32 PM, Tobias Pape <<a href="mailto:Das.Linux@gmx.de">Das.Linux@gmx.de</a>> wrote:<br>
>> ><br>
>> > > On 15.06.2017, at 21:22, Chris Cunningham <<a href="mailto:cunningham.cb@gmail.com">cunningham.cb@gmail.com</a>><br>
>> > > wrote:<br>
>> > ><br>
>> > > #testMissingThenAdd:  ?<br>
>> > ><br>
>> ><br>
>> > #isAdding:<br>
>> > #ingests:<br>
>> ><br>
>> > #wasAbsentButNowIsPresent:<br>
>> ><br>
>> > (just rambling…)<br>
>> ><br>
>> > I like added:.  Its concise, accurate and reads nicely:<br>
>><br>
>><br>
>> Ok, but then maybe #addedNew: ? So as we know more than just an adding<br>
>> operation succeeded… :)<br>
><br>
><br>
> So it reads:<br>
><br>
> ^self select: [:each| seen addedNew: each]<br>
><br>
> I like that how that reads.<br>
><br>
> #added: wasn't bad - but I could see myself thinking it meant roughly 'was<br>
> this value already in the collection'?  Which misses the add part and is<br>
> backwards on the result (true if present, false if added).<br>
><br>
> -cbc<br>
>><br>
>><br>
>> ><br>
>> > withoutDuplicates<br>
>> >       "Answer a copy of the receiver that preserves order but eliminates<br>
>> > any duplicates."<br>
>> >       | seen |<br>
>> >       seen := Set new: self size.<br>
>> >       ^self select: [:each| seen added: each]<br>
>> ><br>
>> > messagesDo: aBlock<br>
>> >       "Evaluate aBlock exactly once with all the message selectors sent<br>
>> > by me."<br>
>> ><br>
>> >       | scanner aSet |<br>
>> >       self isQuick ifTrue: [ ^self ].<br>
>> >       scanner := InstructionStream on: self.<br>
>> >       scanner scanFor: [ :x |<br>
>> >               | selector |<br>
>> >               (selector := scanner selectorToSendOrSelf) == scanner<br>
>> > ifFalse: [<br>
>> >                       ((aSet ifNil: [ aSet := IdentitySet new ]) added:<br>
>> > selector) ifTrue: [<br>
>> >                               aBlock value: selector ] ].<br>
>> >               false "keep scanning" ]<br>
>> ><br>
>> ><br>
>> ><br>
>> > > On Jun 15, 2017 12:19 PM, "Eliot Miranda" <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>><br>
>> > > wrote:<br>
>> > > Hi Tobias,<br>
>> > ><br>
>> > > On Thu, Jun 15, 2017 at 12:06 PM, Tobias Pape <<a href="mailto:Das.Linux@gmx.de">Das.Linux@gmx.de</a>><br>
>> > > wrote:<br>
>> > ><br>
>> > > > On 15.06.2017, at 20:30, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>><br>
>> > > > wrote:<br>
>> > > ><br>
>> > > > Hi Levente, Hi Chris,<br>
>> > > ><br>
>> > > > On Wed, Jun 14, 2017 at 1:10 PM, Levente Uzonyi<br>
>> > > > <<a href="mailto:leves@caesar.elte.hu">leves@caesar.elte.hu</a>> wrote:<br>
>> > > > On Wed, 14 Jun 2017, <a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a> wrote:<br>
>> > > ><br>
>> > > > Eliot Miranda uploaded a new version of Collections to project The<br>
>> > > > Trunk:<br>
>> > > > <a href="http://source.squeak.org/trunk/Collections-eem.756.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/<wbr>trunk/Collections-eem.756.mcz</a><br>
>> > > ><br>
>> > > > ==================== Summary ====================<br>
>> > > ><br>
>> > > > Name: Collections-eem.756<br>
>> > > > Author: eem<br>
>> > > > Time: 14 June 2017, 11:03:24.917631 am<br>
>> > > > UUID: 8d7c03bc-1cdb-44c7-9173-<wbr>10d50c0dae29<br>
>> > > > Ancestors: Collections-eem.755<br>
>> > > ><br>
>> > > > Add SequenceableCollection>><wbr>withoutDuplicates for a more elegant fix<br>
>> > > > to MailMessage>>to:<br>
>> > > ><br>
>> > > > =============== Diff against Collections-eem.755 ===============<br>
>> > > ><br>
>> > > > Item was added:<br>
>> > > > + ----- Method: SequenceableCollection>><wbr>withoutDuplicates (in<br>
>> > > > category 'copying') -----<br>
>> > > > + withoutDuplicates<br>
>> > > > +       "Answer a copy of the receiver that preserves order but<br>
>> > > > eliminates any duplicates."<br>
>> > > > +       | seen |<br>
>> > > > +       seen := Set new: self size.<br>
>> > > > +       ^self select: [:each|<br>
>> > > > +                                 (seen includes: each)<br>
>> > > > +                                       ifTrue: [false]<br>
>> > > > +                                       ifFalse: [seen add: each.<br>
>> > > > true]]!<br>
>> > > ><br>
>> > > > What a great opportunity to use #addNewElement::<br>
>> > > ><br>
>> > > >         ^self select: [ :each | seen addNewElement: each ]<br>
>> > > ><br>
>> > > > I love the functionality but I don't like the selector. It seems to<br>
>> > > > imply that one must only add a new element.  So why not call this something<br>
>> > > > like addIfAbsent: ?<br>
>> > > ><br>
>> > > > Here are some suggestions.  Votes?<br>
>> > > > - don't change it; stick with addNewElement:<br>
>> > > > - addIfAbsent:<br>
>> > > > - ifAbsentAdd:<br>
>> > > > - ifMissingAdd:<br>
>> > > ><br>
>> > > > I think I prefer ifAbsentAdd: cuz addIfAbsent: looks too much like a<br>
>> > > > potential spelling error, and conflicts with typical ifAbsent: arguments<br>
>> > > > supplying exception blocks.  But I could go with ifMissingAdd: because it is<br>
>> > > > more distinctive.<br>
>> > ><br>
>> > > Well, we do have<br>
>> > ><br>
>> > >         Collection>>addIfNotPresent:<br>
>> > ><br>
>> > > So why invent a new one?<br>
>> > ><br>
>> > > Because addIfNotPresent: answers its argument and we need one that<br>
>> > > answers whether the element was absent.  So alas addIfNotPresent: is not a<br>
>> > > suitable candidate.<br>
>> > ><br>
>> > ><br>
>> > > I think the important thing with #addNewElement: is that it returns<br>
>> > > *whether* it added a new element<br>
>> > > but then again it breaks the tradition of #add* returning its<br>
>> > > argument…<br>
>> > ><br>
>> > > a very clear and very strange one that would reveal that a boolean is<br>
>> > > returned would be #isAbsentAndIfSoAdd: …<br>
>> > ><br>
>> > > wasAbsentAdding: or ifWasAbsentAdding: would be less cumbersome but I<br>
>> > > like something snappier that people will remember.  ifMissingAdd: looks good<br>
>> > > because it doesn't conflict with the add*: methods answering their argument,<br>
>> > > and the ifMissing implies the answer is true if the element wasn't already<br>
>> > > present.<br>
>> > ><br>
>> > > Stéphane, can you live with ifMissingAdd: ?  Chris?<br>
>> > ><br>
>> > > Best regards<br>
>> > >         -Tobias<br>
>> > ><br>
>> > > > _,,,^..^,,,_<br>
>> > > > best, Eliot<br>
>> > ><br>
>> > > _,,,^..^,,,_<br>
>> > > best, Eliot<br>
>> ><br>
>> > _,,,^..^,,,_<br>
>> > best, Eliot<br>
>> ><br>
>><br>
>><br>
><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div></div>