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