Mantis - Squeak
Viewing Issue Advanced Details
7095 Collections major always 06-13-08 07:27 04-18-10 22:05
none trunk  
0007095: Dictionary>>collect: answers OrderedCollection not Dictionary
Which is clearly wrong. Attached change set fixes it and also provides tests to cover the behavior of #select:, #reject: and #collect:.
Here is what ANSI says: Message Refinement: collect: transformer
Answer a new collection constructed by gathering the results of evaluating transformer with each element of the receiver.

Definition: <collection>
For each element of the receiver, transformer is evaluated with the element as the parameter. The results of these evaluations are collected into a new collection. The elements are traversed in the order specified by the #do: message for the receiver. Unless specifically refined, this message is defined to answer an object conforming to the same protocol as the receiver.

Refinement: <abstractDictionary>
Answer a new instance of the receiver's type with the same keys. For each key of the answer, a new element is obtained by evaluating transformer with the corresponding element of the receiver as the parameter.
 DictCollect-ar.cs [^] (2,799 bytes) 06-13-08 07:27

nicolas cellier   
07-03-08 20:42   
"fix begin"
Installer mantis bug: 7095 fix: 'DictCollect-ar.cs'.
"fix test"
"fix end"

nicolas cellier   
07-03-08 20:52   
I support this request as the most logical of the month.

Two good reasons to not answer an OrderedCollection are:

1) Dictionary behaves more like Bag than OrderedCollection because Dictionary values are Unordered (order is arbitrary and can change at any time if Dictionary happens to grow).
2) Answering an OrderedCollection is an operation
 - replacing user assigned crafted keys
 - with totally arbitrarily assigned keys (from: 1 to: self size)

Some discussion on squeak-dev incorrectly stated that Dictionary should return anOrderedCollection because a collection of values is expected...
But wait, what a Dictionary is? Just a Bag of values with user assigned keys!
So answering a Dictionary is the clever thing to do, that's not only an opinion, that's facts.
12-17-08 04:40   
I suspect that this might break things
nicolas cellier   
09-25-09 20:39   
Fixed in [^] [^]