AW: [squeak-dev] IdentitySet>>collect:

Florin Mateoc florin.mateoc at gmail.com
Thu Nov 27 01:23:36 UTC 2014


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



More information about the Squeak-dev mailing list