Hi there
A question to test your sagacity :) I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not. that is: #((1 2 3) (4 5 6)) flatten --> #(1 2 3 4 5 6) #(1 2 3 4 5 6) flatten --> #(1 2 3 4 5 6) #((1 2 3) 4 5 6) flatten --> #(1 2 3 4 5 6) Any idea about the best implementation for this? -- Simon _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
flatCollect: ?
Stef On Aug 27, 2010, at 2:06 PM, Simon Denier wrote: > Hi there > > A question to test your sagacity :) > > I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not. > > > that is: > #((1 2 3) (4 5 6)) flatten --> #(1 2 3 4 5 6) > > #(1 2 3 4 5 6) flatten --> #(1 2 3 4 5 6) > > #((1 2 3) 4 5 6) flatten --> #(1 2 3 4 5 6) > > > Any idea about the best implementation for this? > > > -- > Simon > > > > > _______________________________________________ > Pharo-users mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
In reply to this post by Simon Denier-3
no flatCollect does not work.
> that is: > #((1 2 3) (4 5 6)) flatten --> #(1 2 3 4 5 6) > > #(1 2 3 4 5 6) flatten --> #(1 2 3 4 5 6) > > #((1 2 3) 4 5 6) flatten --> #(1 2 3 4 5 6) > > > Any idea about the best implementation for this? > > > -- > Simon > > > > > _______________________________________________ > Pharo-users mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
In reply to this post by Stéphane Ducasse
There is a #gather:
which takes a collection of collections and answers a single collection. (if i remember correctly). On 27 August 2010 16:10, Stéphane Ducasse <[hidden email]> wrote: > flatCollect: ? > > Stef > > On Aug 27, 2010, at 2:06 PM, Simon Denier wrote: > >> Hi there >> >> A question to test your sagacity :) >> >> I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not. >> >> >> that is: >> #((1 2 3) (4 5 6)) flatten --> #(1 2 3 4 5 6) >> >> #(1 2 3 4 5 6) flatten --> #(1 2 3 4 5 6) >> >> #((1 2 3) 4 5 6) flatten --> #(1 2 3 4 5 6) >> >> >> Any idea about the best implementation for this? >> >> >> -- >> Simon >> >> >> >> >> _______________________________________________ >> Pharo-users mailing list >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users > > > _______________________________________________ > Pharo-users mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users > -- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
yes this is the same as flatCollect: in moose.
gather: aBlock ^ Array streamContents: [:stream | self do: [:ea | stream nextPutAll: (aBlock value: ea)]] On Aug 27, 2010, at 3:13 PM, Igor Stasenko wrote: > There is a #gather: > which takes a collection of collections and answers a single collection. > (if i remember correctly). > > On 27 August 2010 16:10, Stéphane Ducasse <[hidden email]> wrote: >> flatCollect: ? >> >> Stef >> >> On Aug 27, 2010, at 2:06 PM, Simon Denier wrote: >> >>> Hi there >>> >>> A question to test your sagacity :) >>> >>> I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not. >>> >>> >>> that is: >>> #((1 2 3) (4 5 6)) flatten --> #(1 2 3 4 5 6) >>> >>> #(1 2 3 4 5 6) flatten --> #(1 2 3 4 5 6) >>> >>> #((1 2 3) 4 5 6) flatten --> #(1 2 3 4 5 6) >>> >>> >>> Any idea about the best implementation for this? >>> >>> >>> -- >>> Simon >>> >>> >>> >>> >>> _______________________________________________ >>> Pharo-users mailing list >>> [hidden email] >>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users >> >> >> _______________________________________________ >> Pharo-users mailing list >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users >> > > > > -- > Best regards, > Igor Stasenko AKA sig. > > _______________________________________________ > Pharo-users mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Yep flatten calls gather:, and flatCollect: has a different implementation, but all expects a recursive collection, not a flat one. Well we will find a workaround for now. On 27 août 2010, at 15:23, Stéphane Ducasse wrote: > yes this is the same as flatCollect: in moose. > > > gather: aBlock > ^ Array streamContents: > [:stream | > self do: [:ea | stream nextPutAll: (aBlock value: ea)]] > > On Aug 27, 2010, at 3:13 PM, Igor Stasenko wrote: > >> There is a #gather: >> which takes a collection of collections and answers a single collection. >> (if i remember correctly). >> >> On 27 August 2010 16:10, Stéphane Ducasse <[hidden email]> wrote: >>> flatCollect: ? >>> >>> Stef >>> >>> On Aug 27, 2010, at 2:06 PM, Simon Denier wrote: >>> >>>> Hi there >>>> >>>> A question to test your sagacity :) >>>> >>>> I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not. >>>> >>>> >>>> that is: >>>> #((1 2 3) (4 5 6)) flatten --> #(1 2 3 4 5 6) >>>> >>>> #(1 2 3 4 5 6) flatten --> #(1 2 3 4 5 6) >>>> >>>> #((1 2 3) 4 5 6) flatten --> #(1 2 3 4 5 6) >>>> >>>> >>>> Any idea about the best implementation for this? >>>> >>>> >>>> -- >>>> Simon >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> Pharo-users mailing list >>>> [hidden email] >>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users >>> >>> >>> _______________________________________________ >>> Pharo-users mailing list >>> [hidden email] >>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users >>> >> >> >> >> -- >> Best regards, >> Igor Stasenko AKA sig. >> >> _______________________________________________ >> Pharo-users mailing list >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users > > > _______________________________________________ > Pharo-users mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users -- Simon _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Free forum by Nabble | Edit this page |