Collection groupedBy: and groups order

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Collection groupedBy: and groups order

Pharo Smalltalk Developers mailing list
Hello, I found a useful method in the collection - groupedBy: - the result container is some PlugableDictionary (integer variant) and group order (keys) is not preserved.

Would not it be better to choose some other Dictionary variant, which preserve the order of groups (like in source Collection)?

pf

Reply | Threaded
Open this post in threaded view
|

Re: Collection groupedBy: and groups order

Damien Pollet
The problem is, there isn't really an order to preserve in the first place, since even if the original collection is a sequencable one, the elements of each group would be interleaved in it. I could see the point of sorting the keys though.

On Tue, 14 Aug 2018 at 18:32, Petr Fischer via Pharo-dev <[hidden email]> wrote:
Hello, I found a useful method in the collection - groupedBy: - the result container is some PlugableDictionary (integer variant) and group order (keys) is not preserved.

Would not it be better to choose some other Dictionary variant, which preserve the order of groups (like in source Collection)?

pf



--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
Reply | Threaded
Open this post in threaded view
|

Re: Collection groupedBy: and groups order

Stéphane Ducasse
In reply to this post by Pharo Smalltalk Developers mailing list
Hi Petr 

do you have a test illustrating what behavior you think should be good?

Stef
--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France

Reply | Threaded
Open this post in threaded view
|

Re: Collection groupedBy: and groups order

Pharo Smalltalk Developers mailing list
I created two tests, here:

  Gofer it
    url: 'https://dev.cvokhaus.cz/st-public/';
    package: 'CollectionGroupedByOrderTest';
    load.

What do you think?

pf


> Hi Petr
>
> do you have a test illustrating what behavior you think should be good?
>
> Stef
> --------------------------------------------
> Stéphane Ducasse
> http://stephane.ducasse.free.fr
> http://www.synectique.eu / http://www.pharo.org 
> 03 59 35 87 52
> Assistant: Julie Jonas
> FAX 03 59 57 78 50
> TEL 03 59 35 86 16
> S. Ducasse - Inria
> 40, avenue Halley,
> Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
> Villeneuve d'Ascq 59650
> France
>

Reply | Threaded
Open this post in threaded view
|

Re: Collection groupedBy: and groups order

Chris Muller-3
In reply to this post by Damien Pollet
Despite the interleavement, the order of the grouped elements as they
occurred in the original collection could be preserved.

On Wed, Aug 15, 2018 at 6:34 AM, Damien Pollet <[hidden email]> wrote:

> The problem is, there isn't really an order to preserve in the first place,
> since even if the original collection is a sequencable one, the elements of
> each group would be interleaved in it. I could see the point of sorting the
> keys though.
>
> On Tue, 14 Aug 2018 at 18:32, Petr Fischer via Pharo-dev
> <[hidden email]> wrote:
>>
>> Hello, I found a useful method in the collection - groupedBy: - the result
>> container is some PlugableDictionary (integer variant) and group order
>> (keys) is not preserved.
>>
>> Would not it be better to choose some other Dictionary variant, which
>> preserve the order of groups (like in source Collection)?
>>
>> pf
>>
>
>
> --
> Damien Pollet
> type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Collection groupedBy: and groups order

Pharo Smalltalk Developers mailing list
I created test case for desired behaviour:

  Gofer it
    url: 'https://dev.cvokhaus.cz/st-public/';
    package: 'CollectionGroupedByOrderTest';
    load.

pf


> Despite the interleavement, the order of the grouped elements as they
> occurred in the original collection could be preserved.
>
> On Wed, Aug 15, 2018 at 6:34 AM, Damien Pollet <[hidden email]> wrote:
> > The problem is, there isn't really an order to preserve in the first place,
> > since even if the original collection is a sequencable one, the elements of
> > each group would be interleaved in it. I could see the point of sorting the
> > keys though.
> >
> > On Tue, 14 Aug 2018 at 18:32, Petr Fischer via Pharo-dev
> > <[hidden email]> wrote:
> >>
> >> Hello, I found a useful method in the collection - groupedBy: - the result
> >> container is some PlugableDictionary (integer variant) and group order
> >> (keys) is not preserved.
> >>
> >> Would not it be better to choose some other Dictionary variant, which
> >> preserve the order of groups (like in source Collection)?
> >>
> >> pf
> >>
> >
> >
> > --
> > Damien Pollet
> > type less, do more [ | ] http://people.untyped.org/damien.pollet
>