adding methods to Squeak package

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

adding methods to Squeak package

Paul DeBruicker
Hi -


I added Collection>>#groupedBy: and PluggableDictionary
class>>#integerDictionary from Pharo to Gemstone.  Should I add them to
GsPharo-Core or GsSqueakCommon-Core ?

The code that seems to work is pasted below and copied without
modification from Pharo 1.2:



Collection>>#groupedBy: aBlock
       
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."
        | groups |
        groups := PluggableDictionary integerDictionary.
        self do: [ :each |
                (groups at: (aBlock value: each) ifAbsentPut: [ OrderedCollection new
]) add: each ].
        self species ~~ OrderedCollection ifTrue: [
                groups associationsDo: [ :association |
                        association value: (self species withAll: association value) ]].
        ^ groups


PluggableDictionary class>>#integerDictionary
integerDictionary
        ^ self new hashBlock: [:integer | integer hash \\ 1064164 * 1009]


Thanks

Paul
Reply | Threaded
Open this post in threaded view
|

Re: adding methods to Squeak package

Dale Henrichs
Paul,

 From a quick look at Squeak4.x it looks like both of these methods are
Pharo-specific, so they should be added to the GsPharo-Core package..

I suggest that you submit a glassdb issue for this, so that I can keep
track of it...

I want to include this in the upcoming 1.0-beta.8.6 release ...

Dale

On 02/14/2011 06:52 AM, Paul DeBruicker wrote:

> Hi -
>
>
> I added Collection>>#groupedBy: and PluggableDictionary
> class>>#integerDictionary from Pharo to Gemstone.  Should I add them to
> GsPharo-Core or GsSqueakCommon-Core ?
>
> The code that seems to work is pasted below and copied without
> modification from Pharo 1.2:
>
>
>
> Collection>>#groupedBy: aBlock
>
> 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."
> | groups |
> groups := PluggableDictionary integerDictionary.
> self do: [ :each |
> (groups at: (aBlock value: each) ifAbsentPut: [ OrderedCollection new
> ]) add: each ].
> self species ~~ OrderedCollection ifTrue: [
> groups associationsDo: [ :association |
> association value: (self species withAll: association value) ]].
> ^ groups
>
>
> PluggableDictionary class>>#integerDictionary
> integerDictionary
> ^ self new hashBlock: [:integer | integer hash \\ 1064164 * 1009]
>
>
> Thanks
>
> Paul