[squeak-dev] IdentitySet>>collect:

Levente Uzonyi leves at elte.hu
Wed Nov 26 19:01:49 UTC 2014


On Wed, 26 Nov 2014, Eliot Miranda wrote:

> Hi All,
>     IdentitySet>>collect: answers a Set, not an IdentitySet.  Anyone else agree this is a serious bug?  Anyone else disagree?

Sometimes it's feasable to return an IdentitySet, other times it's not, so 
there's no optimal solution - #collect: can't cover all cases.

Set >> #collect: explicitly returns a Set, because this is the least bad 
solution to handle all of its subclasses reasonably well.
In case of WeakSet, returning a WeakSet makes no sense, because some of 
your objects will disappear immediately.
In case of IdentitySet, PluggableSet, KeyedSet and KeyedIdentitySet the 
returned values may not behave well in the original collection.

The best is to always be explicit:

(IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [ :e | e ] as: IdentitySet
"==> an IdentitySet(1 2 3 1.0 2.0 3.0)"

Levente

> 
> WTF??
> 
> (IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [:e| e] a Set(1.0 2 3)
> --
> best,Eliot
> 
>


More information about the Squeak-dev mailing list