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

Peter Kenny peter at pbkresearch.co.uk
Sun Sep 8 08:28:57 EDT 2019

Two comments:
First, the method comment for Collection>>collect:thenDo: is "Utility method
to improve readability", which is exactly the same as for
collect:thenSelect: and collect:thenReject:. This suggests that the
*intention* of the method is not to introduce new behaviour, but simply to
provide a shorthand for the version with parentheses. For other kinds of
collection this is true; just the deduping makes Set different. If we want
the different behaviour, this should be indicated by method name and
Second, if we remove asSet from the second snippet, the output is exactly
the same. It will be the same as long as the original collection has no
duplicates. Somehow the effect is to ignore the asSet. It just smells wrong.

Peter Kenny

Kasper Osterbye wrote
> 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@

> ) 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

Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

More information about the Pharo-users mailing list