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

Steffen Märcker merkste at web.de
Sun Sep 8 03:04:31 EDT 2019


Surprise!

The selector #collect:thenDo: strongly suggests that it behaves just as #collect: then #do:. But as #collect: usually means map + aggregate in the reveiver type, I'd expect the input to the do block to be deduped already. At least it is an easy to miss source of subtle bugs. Maybe an additional method #map:thenDo: would make sense?

Best, Steffen

Am 8. September 2019 08:02:30 MESZ schrieb "Kasper Østerbye" <kasper.osterbye at gmail.com>:
>Feature!
>
>collect: forms a new collection of the same kind as its receiver. In
>this
>case a set. As the result of your collect:
>#(1 2 3) asSet collect: #odd)
>is booleans, the resulting set will contain only to elements (the
>duplicate
>odd resulting in true is removed).
>
>collect: thenDo: applies the collect-block to each element of the
>receiver,
>and then applies the do to each of those results. You can see the
>implementation of collect:thenDo: in class Collection.
>
>Best,
>
>Kasper
>
>
>On 7 September 2019 at 17.22.03, Herby Vojčík (herby at mailbox.sk) wrote:
>
>Hello!
>
>----
>(#(1 2 3) asSet collect: #odd)
>do: [ :each | Transcript show: each; cr ]
>
>> true
>> false
>
>----
>
>#(1 2 3) asSet collect: #odd
>thenDo: [ :each | Transcript show: each; cr ]
>
>> true
>> false
>> true
>----
>
>
>Bug or feature?
>
>Herby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190908/1295c68c/attachment.html>


More information about the Pharo-users mailing list