Hi Since Symbol and Blocks are polymorphic could we not simplify the code to be: SequenceableCollection>>sortedAs: aSortBlockOrSymbol "Answer a SortedCollection whose elements are the elements of the receiver. The sort order is defined by the argument, aSortBlockOrSymbol. The receiver cannot be empty. Answer a new collection. This method does not side effect the receiver. e.g. SequenceableCollection withAllSubclasses sortedAs: #name. SequenceableCollection withAllSubclasses sortedAs: [:class | class methodDict size]." | aSortBlock | aSortBlock := (#(true false ) includes: (aSortBlockOrSymbol value: self first)) ifTrue: [[:a :b | aSortBlockOrSymbol value: a]] ifFalse: [[:a :b | (aSortBlockOrSymbol value: a) < (aSortBlockOrSymbol value: b)]]. ^ (SortedCollection new: self size) sortBlock: aSortBlock; addAll: self; yourself |
SequenceableCollection-sortedAs.st
Description: Binary data
Cheers Carlo On 12 Mar 2014, at 12:32 AM, Pharo4Stef <pharo4s...@free.fr> wrote: Thanks eliot. On 11 Mar 2014, at 20:51, Eliot Miranda <eliot.mira...@gmail.com> wrote:
|