[Pharo-users] Set >> collect:thenDo:

Kasper Østerbye kasper.osterbye at gmail.com
Sun Sep 8 03:50:03 EDT 2019


The first version:

(#(1 2 3) asSet collect: #odd)
do: [ :each | Transcript show: each; cr ]

is rather straight forward I believe, as collect: and do: has been around
forever (relatively speaking).


#(1 2 3) asSet collect: #odd
thenDo: [ :each | Transcript show: each; cr ]


On 8 September 2019 at 09.13.36, Richard Sargent (
richard.sargent at gemtalksystems.com) wrote:

 I am skeptical of one that relies on a specific implementation rather than
a specific definition.

I share your feeling. I am not sure where such a definition would come
from. In Squeak it is defined as:

collect: collectBlock thenDo: doBlock

^ (self collect: collectBlock) do: doBlock

In pharo as:

collect: collectBlock thenDo: doBlock

^ self do: [ :each | doBlock value: (collectBlock value: each)]

I might have called the method collect:eachDo:, but we each have slightly
different styles. What I like about the pharo version is that is a
shorthand for something which is not achieved by mere parentheses.

Best,

Kasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190908/0d9eaf6e/attachment.html>


More information about the Pharo-users mailing list