[squeak-dev] Re: Dictionary>>collect: returning OrderedCollection?

Bert Freudenberg bert at freudenbergs.de
Sat Jun 14 09:32:03 UTC 2008


On 14.06.2008, at 08:26, K. K. Subramaniam wrote:

> On Saturday 14 Jun 2008 6:03:34 am Paolo Bonzini wrote:
>>> associationsCollect: aBlock
>>>       ...
>>>       self associationsDo: [ :assoc | d nextPut: assoc key ->  
>>> (aBlock
>>> value: assoc
>>
>>                value) ].
>>
>> would be very wrong, because associationsSomething: messages work on
>> associations, while your message passes only the value to the  
>> block.  An
>> hypothetical associationsCollect: would do
>>
>> associationsCollect: aBlock
>>         | d |
>>         d := Dictionary new.
>>         self associationsDo: [ :assoc | d add: (aBlock value:  
>> assoc) ]
> I did write it this way initially but then it appeared like an  
> overkill to me
> as we are not changing the keys, only replacing the values  
> associated with
> the keys.
>
> Now we have three ways of defining collect: on a dictionary - values  
> alone,
> on the value part of associations, and on associations.


Shouldn't "associationsCollect:" be equivalent to "associations  
collect:"?

- Bert -





More information about the Squeak-dev mailing list