On 27.11.2014, at 02:23, Florin Mateoc florin.mateoc@gmail.com wrote:
On 11/26/2014 7:14 PM, Levente Uzonyi wrote:
Your example hides the problem of ordering - what Tobias is asking about - so here's another:
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each class ]
If IdentitySet >> #collect: were returning an Array, then what would be the answer?
{ SmallInteger. Float } or { Float. SmallInteger } ?
snip
Levente
Then why does Dictionary>>keys return an Array? Where does the order come from in that example? Similarly, where does the order come from when you invoke collect:as: on a set with Array as an argument? The answer is quite simple: it is the iteration order. collect: is part of the _iteration_ protocol.
I agree with Frank here, for me a more important aspect of collect: is preserving the _mapping_ between the original elements and the collected values. There is no obvious mapping if there are fewer collected values than elements.
Florin
I agree. The order is unimportant, it's a Set after all. What *is* important is getting a collection of the same size back - by default. For other needs we have collect:as:.
- Bert -