[squeak-dev] #gather appears to be working....next idiom is groupedBy:

Tom Beckmann tomjonabc at gmail.com
Sun Oct 25 11:39:52 UTC 2020


Hi timothy,

checkout Squeak's `Collection>>groupBy:`. There are some different
semantics though: Pharo's version will preserve the relative order of the
groups as they first appear in the collection and also return the same
species of Collection nested in the dictionary, while Squeak disregards
order of groups and always returns OrderedCollections.

Since both the naming (group*ed*By: since it returns a copy) and the
properties of the output are more strict in Pharo's version, I would vote
to copy the exact code from Pharo's version in the *Roassal-Squeak
extension category to not break any assumptions from migrated code.

Best,
Tom

On Sun, Oct 25, 2020 at 12:31 PM gettimothy via Squeak-dev <
squeak-dev at lists.squeakfoundation.org> wrote:

> First,
>
> thank you for the 'gather' tip. It appears to work just fine.
>
> Next pharo-ism is something named 'groupedBy:'
>
> Collection >> groupedBy: aBlock
> "Answer a dictionary whose keys are the result of evaluating aBlock for
> all my elements, and the value for each key is the selection of my elements
> that evaluated to that key. Uses species.
>
> Example of use:
> (#(1 2 3 4 5) groupedBy: [ :v | v odd ]) asString >>> 'an
> OrderedDictionary(true->#(1 3 5) false->#(2 4))'
> "
>
>
>
> This looks like 'select:' to me.
>
>
> any objections/insight much appreciated.
>
> thx
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20201025/1f864186/attachment.html>


More information about the Squeak-dev mailing list