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

K. K. Subramaniam subbukk at gmail.com
Fri Jun 13 15:18:29 UTC 2008


On Friday 13 Jun 2008 5:38:37 pm nicolas cellier wrote:
> With all the respect due to the holly blue book and its authors, it is
> not the bible.
Sorry, I didn't mean to throw the book at you. I only quoted the passage to 
point out that collect: is WAD.

That doesn't stop us from adding a new method to create a new dictionary by 
mapping values from an existing dict without affecting its keys. E.g.
        numberDictionary associationsCollect: [ :v | v asWords ].

Here is my first cut at it:

associationsCollect: aBlock
	| d |
	d = WriteStream on: (Array new: self size).
	self associationsDo: [ :assoc | d nextPut: assoc key -> (aBlock value: assoc 
value) ].
	^Dictionary newFrom: d contents

Subbu



More information about the Squeak-dev mailing list