The Inbox: Collections-ct.870.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.870.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.870.mcz

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

Name: Collections-ct.870
Author: ct
Time: 30 December 2019, 3:01:24.515602 pm
UUID: cb75296c-0850-d440-97a6-fc1962eef672
Ancestors: Collections-nice.868

Proposal: Refine Dictionary >> #at:ifPresent: not to require an one-arg block.

Usage example:
        Smalltalk at: className ifPresent: [self inform: 'Class already exists'. ^ nil].

=============== Diff against Collections-nice.868 ===============

Item was changed:
  ----- Method: Dictionary>>at:ifPresent: (in category 'accessing') -----
  at: key ifPresent: aBlock
  "Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer nil."
 
  | v |
  v := self at: key ifAbsent: [^ nil].
+ ^ aBlock cull: v
- ^ aBlock value: v
  !


Reply | Threaded
Open this post in threaded view
|

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

Levente Uzonyi
On Mon, 30 Dec 2019, [hidden email] wrote:

> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-ct.870.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ct.870
> Author: ct
> Time: 30 December 2019, 3:01:24.515602 pm
> UUID: cb75296c-0850-d440-97a6-fc1962eef672
> Ancestors: Collections-nice.868
>
> Proposal: Refine Dictionary >> #at:ifPresent: not to require an one-arg block.
>
> Usage example:
> Smalltalk at: className ifPresent: [self inform: 'Class already exists'. ^ nil].

That is what Dictionary >> #includesKey: is for:

  (Smalltalk includesKey: className) ifTrue: [self inform: 'Class already exists'. ^ nil].

Btw, classes should be looked up with #hasClassNamed::

  (Smalltalk hasClassNamed: className) ifTrue: [self inform: 'Class already exists'. ^ nil].


Levente

>
> =============== Diff against Collections-nice.868 ===============
>
> Item was changed:
>  ----- Method: Dictionary>>at:ifPresent: (in category 'accessing') -----
>  at: key ifPresent: aBlock
>   "Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer nil."
>
>   | v |
>   v := self at: key ifAbsent: [^ nil].
> + ^ aBlock cull: v
> - ^ aBlock value: v
>  !

Reply | Threaded
Open this post in threaded view
|

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

Christoph Thiede

Ah, thank you!


Then this can be moved to Treated.


Von: Squeak-dev <[hidden email]> im Auftrag von Levente Uzonyi <[hidden email]>
Gesendet: Montag, 30. Dezember 2019 15:27:28
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.870.mcz
 
On Mon, 30 Dec 2019, [hidden email] wrote:

> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-ct.870.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ct.870
> Author: ct
> Time: 30 December 2019, 3:01:24.515602 pm
> UUID: cb75296c-0850-d440-97a6-fc1962eef672
> Ancestors: Collections-nice.868
>
> Proposal: Refine Dictionary >> #at:ifPresent: not to require an one-arg block.
>
> Usage example:
>        Smalltalk at: className ifPresent: [self inform: 'Class already exists'. ^ nil].

That is what Dictionary >> #includesKey: is for:

         (Smalltalk includesKey: className) ifTrue: [self inform: 'Class already exists'. ^ nil].

Btw, classes should be looked up with #hasClassNamed::

         (Smalltalk hasClassNamed: className) ifTrue: [self inform: 'Class already exists'. ^ nil].


Levente

>
> =============== Diff against Collections-nice.868 ===============
>
> Item was changed:
>  ----- Method: Dictionary>>at:ifPresent: (in category 'accessing') -----
>  at: key ifPresent: aBlock
>        "Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer nil."
>
>        | v |
>        v := self at: key ifAbsent: [^ nil].
> +      ^ aBlock cull: v
> -      ^ aBlock value: v
>  !



Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

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

Nicolas Cellier
Done

Le lun. 30 déc. 2019 à 15:43, Thiede, Christoph <[hidden email]> a écrit :

Ah, thank you!


Then this can be moved to Treated.


Von: Squeak-dev <[hidden email]> im Auftrag von Levente Uzonyi <[hidden email]>
Gesendet: Montag, 30. Dezember 2019 15:27:28
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.870.mcz
 
On Mon, 30 Dec 2019, [hidden email] wrote:

> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-ct.870.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ct.870
> Author: ct
> Time: 30 December 2019, 3:01:24.515602 pm
> UUID: cb75296c-0850-d440-97a6-fc1962eef672
> Ancestors: Collections-nice.868
>
> Proposal: Refine Dictionary >> #at:ifPresent: not to require an one-arg block.
>
> Usage example:
>        Smalltalk at: className ifPresent: [self inform: 'Class already exists'. ^ nil].

That is what Dictionary >> #includesKey: is for:

         (Smalltalk includesKey: className) ifTrue: [self inform: 'Class already exists'. ^ nil].

Btw, classes should be looked up with #hasClassNamed::

         (Smalltalk hasClassNamed: className) ifTrue: [self inform: 'Class already exists'. ^ nil].


Levente

>
> =============== Diff against Collections-nice.868 ===============
>
> Item was changed:
>  ----- Method: Dictionary>>at:ifPresent: (in category 'accessing') -----
>  at: key ifPresent: aBlock
>        "Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer nil."
>
>        | v |
>        v := self at: key ifAbsent: [^ nil].
> +      ^ aBlock cull: v
> -      ^ aBlock value: v
>  !