Is this multisort feature available for Pharo somewhere?

Regards!


Esteban A. Maringolo


2014-03-12 7:45 GMT-03:00 Nicolas Cellier <nicolas.cellier.aka.n...@gmail.com>:
> I presume you all know about Griggs work on the subject
>
> http://stackoverflow.com/questions/8204826/smalltalk-sort-a-collection-by-two-criteria
> http://objology.blogspot.com/2010/11/tag-sortfunctions.html
>
>
> 2014-03-12 11:23 GMT+01:00 carlo.t <snoob...@yahoo.ie>:
>
>> Hi Otto
>>
>> I think the main reason is to support the second usage scenario:
>> SequenceableCollection withAllSubclasses sortedAs: [:class | class
>> methodDict size].
>> We could try and unify the sort: method to take only blocks while
>> sortedAs:
>> a symbol but then at the same time we could just put everything into one
>> method and use cull: perhaps to handle all the scenarios.
>>
>> Personally I don't feel too comfortable with the code below, apart from
>> the
>> performance penalties it also feels like code that is too 'clever' for
>> itself which obviously makes it complicated to understand and modify. I
>> wrote it mainly for people to voice opinions and get ideas flowing. I'd
>> have
>> 2 separate sort methods so that users can choose if they want the runtime
>> characteristics of either.
>>
>> Example which can handle all current scenarios i.e. symbol or block taking
>> 1
>> or 2 arguments:
>> SequenceableCollection>>sort: aSortBlock
>>         self
>>                 mergeSortFrom: 1
>>                 to: self size
>>                 by: (self createSortBlock:  aSortBlock)
>>
>>
>> SequenceableCollection>>createSortBlock: aSortBlockOrSymbol
>>         ^ aSortBlockOrSymbol numArgs < 2
>>                 ifTrue: [[ :a :b | (#(true false )
>>                                         includes: (aSortBlockOrSymbol
>> value: a))
>>                                 ifTrue: [ aSortBlockOrSymbol value: a]
>>                                 ifFalse: [(aSortBlockOrSymbol value: a) <
>> (aSortBlockOrSymbol value:
>> b)]]]
>>                 ifFalse: [[:a :b | aSortBlockOrSymbol cull: a cull: b]]
>>
>>
>> BTW the previous versions had a bug where it fails when called on an empty
>> collection as the true/false check is done eagerly.
>>
>> Cheers
>> Carlo
>>
>>
>>
>> --
>> View this message in context:
>> http://forum.world.st/Sort-by-property-tp4748500p4748757.html
>> Sent from the Pharo Smalltalk Developers mailing list archive at
>> Nabble.com.
>>
>

Reply via email to