[squeak-dev] IdentitySet>>collect:
Bert Freudenberg
bert at freudenbergs.de
Thu Nov 27 07:57:06 UTC 2014
On 27.11.2014, at 02:23, Florin Mateoc <florin.mateoc at 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 -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4142 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20141127/f66f077d/smime.bin
More information about the Squeak-dev
mailing list
|