AW: [squeak-dev] IdentitySet>>collect:
Levente Uzonyi
leves at elte.hu
Thu Nov 27 00:14:30 UTC 2014
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 } ?
If you really want to have the resulting collection have the same size,
but avoid the problem with ordering, then what you really need is a Bag.
Luckily you can have whatever you want (as long as it makes sense):
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: Set.
"==> a Set(1)"
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: IdentitySet.
"==> an IdentitySet(1)"
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: Array.
"==> #(1 1)"
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: OrderedCollection.
"==> an OrderedCollection(1 1)."
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: Bag.
"==> a Bag(1 1)"
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: IdentityBag.
"==> an IdentityBag(1 1)"
(IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as: Heap.
"==> a Heap(1 1)"
Levente
On Thu, 27 Nov 2014, Frank Lesser wrote:
> Hi Tobias,
> agree, a problem of "OrderedCollection"
> not to break a lot of other things we could return an Array.
> but for me collecting has priority.
> Frank
>
> -----Ursprüngliche Nachricht-----
> Von: squeak-dev-bounces at lists.squeakfoundation.org
> [mailto:squeak-dev-bounces at lists.squeakfoundation.org] Im Auftrag von Tobias
> Pape
> Gesendet: Donnerstag, 27. November 2014 00:48
> An: The general-purpose Squeak developers list
> Betreff: Re: [squeak-dev] IdentitySet>>collect:
>
>
> On 27.11.2014, at 00:34, Frank Lesser <frank-lesser at lesser-software.com>
> wrote:
>
>> hmm, not convinced
>>
>> (IdentitySet withAll: #(1 1.0)) collect: [:e| e asInteger ]
>> OrderedCollection(1 1 )
>>
>> in LSWVST ( one-to-one ), you collect results of evaluating a block on
>> objects.
>>
>> Frank
>> maybe I am wrong ...
>
> Where would the order come from for that _Ordered_Collection?
>
> Best
> -Tobias
>
>
>
More information about the Squeak-dev
mailing list
|