The Inbox: Collections-ct.872.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-ct.872.mcz

commits-2
Christoph Thiede uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.872.mcz

==================== Summary ====================

Name: Collections-ct.872
Author: ct
Time: 20 January 2020, 12:26:15.859545 am
UUID: 9d48e360-1121-6541-ba00-1d06311f2f0c
Ancestors: Collections-nice.870

Implement #at:ifPresent: on SequenceableCollection

Text theQuickBrownFox at: 42 ifPresent: [:char |
        self inform: ({char.char} joinSeparatedBy: $.) asUppercase].

=============== Diff against Collections-nice.870 ===============

Item was added:
+ ----- Method: SequenceableCollection>>at:ifPresent: (in category 'accessing') -----
+ at: index ifPresent: aBlock
+
+ ^ self at: index ifPresent: aBlock ifAbsent: []!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.872.mcz

Eliot Miranda-2
Hi Christoph,


> On Jan 19, 2020, at 3:26 PM, [hidden email] wrote:
>
> Christoph Thiede uploaded a new version of Collections to project The Inbox:
> http://source.squeak.org/inbox/Collections-ct.872.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ct.872
> Author: ct
> Time: 20 January 2020, 12:26:15.859545 am
> UUID: 9d48e360-1121-6541-ba00-1d06311f2f0c
> Ancestors: Collections-nice.870
>
> Implement #at:ifPresent: on SequenceableCollection
>
> Text theQuickBrownFox at: 42 ifPresent: [:char |
>    self inform: ({char.char} joinSeparatedBy: $.) asUppercase].
>
> =============== Diff against Collections-nice.870 ===============
>
> Item was added:
> + ----- Method: SequenceableCollection>>at:ifPresent: (in category 'accessing') -----
> + at: index ifPresent: aBlock
> +
> +    ^ self at: index ifPresent: aBlock ifAbsent: []!

Why is this in SequenceableCollection abd not KeyedCollection?  Would it not work if implemented in Collection itself? Methods shouldn’t as general as possible. For e smoke, just because one needs a method to operate in Strings doesn’t mean it is t more useful higher up in ArrayedCollection.  Thought extended here pays dividends later on.

>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.872.mcz

Christoph Thiede

Hi Eliot,


not sure if I understand you correctly. You suggest to be as generic as possible, or you don't?

I think as we already define #at:ifAbsent: and #at:ifPresent:ifAbsent: on SequenceableCollection, it would be only consistent to implement #at:ifPresent: here as well.


What should be a KeyedCollection? KeyedSet already implements #at:ifPresent:.


Would it not work if implemented in Collection itself?


I cannot imagine, because for example, a Set does not implement #at: ...


Best,
Christoph

Von: Squeak-dev <[hidden email]> im Auftrag von Eliot Miranda <[hidden email]>
Gesendet: Montag, 20. Januar 2020 03:52:52
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.872.mcz
 
Hi Christoph,


> On Jan 19, 2020, at 3:26 PM, [hidden email] wrote:
>
> Christoph Thiede uploaded a new version of Collections to project The Inbox:
> http://source.squeak.org/inbox/Collections-ct.872.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ct.872
> Author: ct
> Time: 20 January 2020, 12:26:15.859545 am
> UUID: 9d48e360-1121-6541-ba00-1d06311f2f0c
> Ancestors: Collections-nice.870
>
> Implement #at:ifPresent: on SequenceableCollection
>
> Text theQuickBrownFox at: 42 ifPresent: [:char |
>    self inform: ({char.char} joinSeparatedBy: $.) asUppercase].
>
> =============== Diff against Collections-nice.870 ===============
>
> Item was added:
> + ----- Method: SequenceableCollection>>at:ifPresent: (in category 'accessing') -----
> + at: index ifPresent: aBlock
> +
> +    ^ self at: index ifPresent: aBlock ifAbsent: []!

Why is this in SequenceableCollection abd not KeyedCollection?  Would it not work if implemented in Collection itself? Methods shouldn’t as general as possible. For e smoke, just because one needs a method to operate in Strings doesn’t mean it is t more useful higher up in ArrayedCollection.  Thought extended here pays dividends later on.

>
>



Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.872.mcz

Chris Muller-3
In reply to this post by Eliot Miranda-2
Hi Eliot,

I agree with your point that methods shouldn't be more general than they need to be, but this isn't one of those cases.  SequenceableCollection already behaves like a keyed collection with #at:, #at:ifAbsent:, and #at:ifPresent:ifAbsent:.  I use them all the time, and sometimes I have an empty block for the ifAbsent:.

+1 for this in trunk after the 5.3 release.



 
> On Jan 19, 2020, at 3:26 PM, [hidden email] wrote:
>
> Christoph Thiede uploaded a new version of Collections to project The Inbox:
> http://source.squeak.org/inbox/Collections-ct.872.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ct.872
> Author: ct
> Time: 20 January 2020, 12:26:15.859545 am
> UUID: 9d48e360-1121-6541-ba00-1d06311f2f0c
> Ancestors: Collections-nice.870
>
> Implement #at:ifPresent: on SequenceableCollection
>
> Text theQuickBrownFox at: 42 ifPresent: [:char |
>    self inform: ({char.char} joinSeparatedBy: $.) asUppercase].
>
> =============== Diff against Collections-nice.870 ===============
>
> Item was added:
> + ----- Method: SequenceableCollection>>at:ifPresent: (in category 'accessing') -----
> + at: index ifPresent: aBlock
> +
> +    ^ self at: index ifPresent: aBlock ifAbsent: []!

Why is this in SequenceableCollection abd not KeyedCollection? Would it not work if implemented in Collection itself? Methods shouldn’t as general as possible. For e smoke, just because one needs a method to operate in Strings doesn’t mean it is t more useful higher up in ArrayedCollection.  Thought extended here pays dividends later on.

>
>