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

Frank Lesser frank-lesser at lesser-software.com
Thu Nov 27 08:21:46 UTC 2014


hmm 
( Set withAll: #( 1 -1 )) collect: [  : e | e abs ] a Set(1)

-----Ursprüngliche Nachricht-----
Von: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] Im Auftrag von Bert
Freudenberg
Gesendet: Donnerstag, 27. November 2014 08:57
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] IdentitySet>>collect:

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 -






More information about the Squeak-dev mailing list