[squeak-dev] Re: Dictionary>>collect: returning OrderedCollection?
K. K. Subramaniam
subbukk at gmail.com
Sat Jun 14 06:26:09 UTC 2008
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.
Subbu
More information about the Squeak-dev
mailing list
|