Skip to content

Commit

Permalink
move extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
akevalion committed Oct 10, 2023
1 parent 992be5f commit cddccdb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Roassal-Layouts/SequenceableCollection.extension.st
Expand Up @@ -8,3 +8,27 @@ SequenceableCollection >> rsSwapElement: u withElement: v [
self at: index2 put: u.
self at: index1 put: v
]

{ #category : #'*Roassal-Layouts' }
SequenceableCollection >> sortedAs: aSortBlockOrSymbol [
"Answer a SortedCollection whose elements are the elements of the
receiver. The sort order is defined by the argument, aSortBlock."

| aSortedCollection aSortBlock |
aSortedCollection := SortedCollection new: self size.
aSortBlock :=
aSortBlockOrSymbol isSymbol
ifTrue: [ [:a :b | |t1 t2|
t1 := (a perform: aSortBlockOrSymbol).
t2 := (b perform: aSortBlockOrSymbol).
((t1 isKindOf: Boolean) and: [t2 isKindOf: Boolean])
ifTrue: [ t1 ]
ifFalse: [ t1 < t2 ] ] ]
ifFalse: [
(aSortBlockOrSymbol numArgs = 1)
ifTrue: [ [ :v1 :v2 | (aSortBlockOrSymbol value: v1) < (aSortBlockOrSymbol value: v2) ] ]
ifFalse: [ aSortBlockOrSymbol ] ].
aSortedCollection sortBlock: aSortBlock.
aSortedCollection addAll: self.
^ aSortedCollection
]

0 comments on commit cddccdb

Please sign in to comment.