[squeak-dev] #species vs OrderedColleciton
Levente Uzonyi
leves at caesar.elte.hu
Tue Dec 27 16:45:39 UTC 2016
On Tue, 27 Dec 2016, Tobias Pape wrote:
>
> On 25.12.2016, at 17:09, Levente Uzonyi <leves at caesar.elte.hu> wrote:
>
>> Hi All,
>>
>> We had a discussion[1] about #species, in the context of Sets and IdentitySets, and its multiple roles which it cannot fulfill[2].
>> A similar issue arises in case of OrderedCollection and its subclasses, but with a smoother resolution, because an OrderedCollection is always an acceptable result (for #collect:).
>> So, I suggest we should change OrderedCollection >> #collect: to always return an OrderedCollection. This change obviously would not affect OrderedCollection, but we already have the same override in SortedCollection.
>>
>> Example:
>>
>> Currently the following raises and error:
>>
>> (FloatCollection withAll: #(1 2 3)) collect: #asString
>>
>> Of course, #collect:as: works as expected:
>>
>> (FloatCollection withAll: #(1 2 3)) collect: #asString as: OrderedCollection
>> "==> an OrderedCollection('1.0' '2.0' '3.0')"
>>
>> So, why not make #collect: behave the same way?
>>
>> This change would make #species not being used in #collect:, which is similar to the solution we have in Set and subclasses.
>> Currently #select: and #copyEmpty also use #species, but no class implements #species in the hierarchy. So, changing #species to return OrderedCollection would have unwanted side effects. (This also shows that #species doesn't solve anything here.)
>>
>> Any objections?
>
> Just a question for clarification, would
>
> (FloatCollection withAll: #(1.0 2.0 3.0)) collect: [:ea | ea sqrt]
>
> result in a FloatCollection or in an OrderedCollection?
An OrderedCollection of course. #collect: would always return an
OrderedCollection.
Levente
>
> Best regards
> -Tobias
>
>>
>>
>> Levente
>>
>> [1] http://lists.squeakfoundation.org/pipermail/squeak-dev/2014-November/180766.html
>> [2] http://lists.squeakfoundation.org/pipermail/squeak-dev/2014-November/180809.html
>>
More information about the Squeak-dev
mailing list
|