[squeak-dev] Re: Dictionary>>collect: returning OrderedCollection?
bonzini at gnu.org
Sat Jun 14 00:33:34 UTC 2008
>> Messages inherited from the class Collection -- includes:, do: and
>> other enumeration messages -- are applied to the *values* of the
>> Dictionary. That is, these messages refer to the values of each
>> association in the Dictionary, rather than to the keys or to the
>> associations themselves.
> With all the respect due to the holly blue book and its authors,
> it is not the bible.
Actually, the "modern" view of Dictionary as a "keyed collection with
external keys" (external = given by the user) does not conflict at all
with the blue book definition. Like #do:, #collect: only works on the
values -- but like on the other keyed collections, i.e.
SequenceableCollections, the keys are preserved.
From here, one can define by extension the obvious meaning of #select:
and #reject: for a dictionary. Note that this meaning is different
between sequenceable collections and dictionaries, because answering
false (resp. true) will change the keys of all subsequent values in a
Note that this:
> associationsCollect: aBlock
> self associationsDo: [ :assoc | d nextPut: assoc key -> (aBlock value: assoc
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
| d |
d := Dictionary new.
self associationsDo: [ :assoc | d add: (aBlock value: assoc) ]
and I have nothing against it. :-)
More information about the Squeak-dev