The method is defined on Collection:
-=-=-=-=-=-=-=-=-=-=-=-= 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 ]. aSortedCollection sortBlock: aSortBlock. aSortedCollection addAll: self. ^ aSortedCollection -=-=-=-=-=-=-=-=-=-=-=-=
the idea is to be able to easily sort objects. Often I would to separate object following a boolean property: #(1 2 3 4 5 6 7) sortedAs: #odd ==> a SortedCollection(1 7 3 5 6 2 4)
In the example I gave in the previous email, I want to have method covered before
Alexandre
On 7 Mar 2010, at 19:02, Stéphane Ducasse wrote:
ok but still send the code because right now I do not get it.
Stef
On Mar 7, 2010, at 5:37 PM, Alexandre Bergel wrote:
I method that I wrote some times ago. It sorts collection in a fancy way.
Alexandre
On 7 Mar 2010, at 13:10, Stéphane Ducasse wrote:
what is sortedAs:
STf On Mar 7, 2010, at 3:38 PM, Alexandre Bergel wrote:
Hi!
Here is a short script excerpt I use. view shape rectangle size: 10; fillColor: [ :aMethod | aMethod isCovered ifTrue: [ Color lightRed ] ifFalse: [ Color white ]]. view nodes: (aClass methods sortedAs: #isCovered).
I feel the way the color is set is very verbose. The following are equivalent fillColor: { #isCovered -> #lightRed } fillColor: { [:m | m isCovered] -> #lightRed } fillColor: { #isCovered -> #lightRed . [:m | m isCovered not ] -> #white}
The white color could be the default color is no color is picked up.
In the script above, I also use #sortedAs: to sort my elements. I find this method quite handy. It is defined as an extension of Collection. It is more flexible than Jannik's #sortedBy: and Moose's #sorted:. #sortedAs operates on boolean as well.
Any opinion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev