Set>>collectAll: aBlock

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

Set>>collectAll: aBlock

Bart Gauquie
Dear all,

Another one was: 

Set>>collectAll: aBlock 
  | newSet |
   newSet := Set new: self size.
   array do: [:each | each ifNotNil: [newSet addAll: (aBlock value: each)]].
   ^ newSet

In analogy with addAll: aCollection. If useful, maybe we should provide a more general implementation for Collection instead of only Set I needed so far.

Kind Regards,

Bart

--
imagination is more important than knowledge - Albert Einstein
Logic will get you from A to B. Imagination will take you everywhere - Albert Einstein
Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. - Albert Einstein
The true sign of intelligence is not knowledge but imagination. - Albert Einstein
Gravitation is not responsible for people falling in love. - Albert Einstein

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Set>>collectAll: aBlock

Julian Fitzell-2
Fyi, PackageInfo (and thus base Pharo currently) defines
Collection>>gather: which has basically this behaviour (minus the nil
check). I had this marked as a method for discussion when going
through the VASt/Pharo collection protocols.

I think #collectAll: is problematic as a selector because "All:"
suggests a collection passed as a parameter.

Another possible pattern would be to model after :flatten in Ruby,
though it operates recursively, so it might not be the best name here.
Maybe #gather: is actually fine.

Julian

2009/12/26 Bart Gauquie <[hidden email]>:

> Dear all,
> Another one was:
> Set>>collectAll: aBlock
>   | newSet |
>    newSet := Set new: self size.
>    array do: [:each | each ifNotNil: [newSet addAll: (aBlock value: each)]].
>    ^ newSet
>
> In analogy with addAll: aCollection. If useful, maybe we should provide a
> more general implementation for Collection instead of only Set I needed so
> far.
> Kind Regards,
> Bart
> --
> imagination is more important than knowledge - Albert Einstein
> Logic will get you from A to B. Imagination will take you everywhere -
> Albert Einstein
> Learn from yesterday, live for today, hope for tomorrow. The important thing
> is not to stop questioning. - Albert Einstein
> The true sign of intelligence is not knowledge but imagination. - Albert
> Einstein
> Gravitation is not responsible for people falling in love. - Albert Einstein
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Set>>collectAll: aBlock

Bart Gauquie
Hi,

Gather seems excellent. Could not find it. Don't need the nil check.

Thanks,

Kind Regards,

Bart

On Sat, Dec 26, 2009 at 11:30 PM, Julian Fitzell <[hidden email]> wrote:
Fyi, PackageInfo (and thus base Pharo currently) defines
Collection>>gather: which has basically this behaviour (minus the nil
check). I had this marked as a method for discussion when going
through the VASt/Pharo collection protocols.

I think #collectAll: is problematic as a selector because "All:"
suggests a collection passed as a parameter.

Another possible pattern would be to model after :flatten in Ruby,
though it operates recursively, so it might not be the best name here.
Maybe #gather: is actually fine.

Julian

2009/12/26 Bart Gauquie <[hidden email]>:
> Dear all,
> Another one was:
> Set>>collectAll: aBlock
>   | newSet |
>    newSet := Set new: self size.
>    array do: [:each | each ifNotNil: [newSet addAll: (aBlock value: each)]].
>    ^ newSet
>
> In analogy with addAll: aCollection. If useful, maybe we should provide a
> more general implementation for Collection instead of only Set I needed so
> far.
> Kind Regards,
> Bart
> --
> imagination is more important than knowledge - Albert Einstein
> Logic will get you from A to B. Imagination will take you everywhere -
> Albert Einstein
> Learn from yesterday, live for today, hope for tomorrow. The important thing
> is not to stop questioning. - Albert Einstein
> The true sign of intelligence is not knowledge but imagination. - Albert
> Einstein
> Gravitation is not responsible for people falling in love. - Albert Einstein
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
imagination is more important than knowledge - Albert Einstein
Logic will get you from A to B. Imagination will take you everywhere - Albert Einstein
Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. - Albert Einstein
The true sign of intelligence is not knowledge but imagination. - Albert Einstein
Gravitation is not responsible for people falling in love. - Albert Einstein

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Set>>collectAll: aBlock

Stéphane Ducasse
In reply to this post by Julian Fitzell-2
Over the years we made a little library with collection extensions
We reevaluated when porting Moose to Pharo.
May be this is the time for people to have a look

        Moose/CollectionExtensions or something like that

        We use it daily for moose. some of the problems we got where that
        Stream sucked.... could only work on array and strings. So we use Nile.
        Now we should evaluate.
                flatCollect: is a cool one.
        Normally we even have tests :)

Stef



On Dec 26, 2009, at 11:30 PM, Julian Fitzell wrote:

> Fyi, PackageInfo (and thus base Pharo currently) defines
> Collection>>gather: which has basically this behaviour (minus the nil
> check). I had this marked as a method for discussion when going
> through the VASt/Pharo collection protocols.
>
> I think #collectAll: is problematic as a selector because "All:"
> suggests a collection passed as a parameter.
>
> Another possible pattern would be to model after :flatten in Ruby,
> though it operates recursively, so it might not be the best name here.
> Maybe #gather: is actually fine.
>
> Julian
>
> 2009/12/26 Bart Gauquie <[hidden email]>:
>> Dear all,
>> Another one was:
>> Set>>collectAll: aBlock
>>   | newSet |
>>    newSet := Set new: self size.
>>    array do: [:each | each ifNotNil: [newSet addAll: (aBlock value: each)]].
>>    ^ newSet
>>
>> In analogy with addAll: aCollection. If useful, maybe we should provide a
>> more general implementation for Collection instead of only Set I needed so
>> far.
>> Kind Regards,
>> Bart
>> --
>> imagination is more important than knowledge - Albert Einstein
>> Logic will get you from A to B. Imagination will take you everywhere -
>> Albert Einstein
>> Learn from yesterday, live for today, hope for tomorrow. The important thing
>> is not to stop questioning. - Albert Einstein
>> The true sign of intelligence is not knowledge but imagination. - Albert
>> Einstein
>> Gravitation is not responsible for people falling in love. - Albert Einstein
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project