added: #sortByApplying:
authorClaus Gittinger <cg@exept.de>
Wed, 20 Jan 2010 10:55:32 +0100
changeset 12647 c1220f82057d
parent 12646 ee2144f97338
child 12648 d3c1fea8f18d
added: #sortByApplying:
SequenceableCollection.st
--- a/SequenceableCollection.st	Mon Jan 18 14:55:20 2010 +0100
+++ b/SequenceableCollection.st	Wed Jan 20 10:55:32 2010 +0100
@@ -358,6 +358,13 @@
     ^ self == SequenceableCollection
 ! !
 
+!SequenceableCollection class methodsFor:'spray'!
+
+sprayTypeName
+	#swAdded.
+	^SOAP::XePName prefix: 'soap' local: 'Array'
+! !
+
 !SequenceableCollection methodsFor:'Compatibility-Squeak'!
 
 allButFirst
@@ -638,6 +645,7 @@
     ^ self replaceFrom:start to:stop with:anArray startingAt:repStart
 ! !
 
+
 !SequenceableCollection methodsFor:'accessing'!
 
 after:anObject
@@ -1926,6 +1934,20 @@
     ^ true
 !
 
+isSoapEncSameAs: comparand
+	"Answer whether the receiver and the <Object> argument, comparand,
+	are considered equivalent in terms of the soap-enc rules."
+
+	| size |
+	#swAdded.
+	self == comparand ifTrue: [^true].
+	self species == comparand species ifFalse: [^false].
+	size := self size.
+	size = comparand size ifFalse: [^false].
+	1 to: size do: [:i | ((self at: i) isSoapEncSameAs: (comparand at: i)) ifFalse: [^false]].
+	^true
+!
+
 sameContentsAs:aCollection whenComparedWith:compareBlock
     "return true if the receiver and aCollection represent collections
      with the same contents, using compareSelector to compare elements.
@@ -5852,6 +5874,7 @@
     "Created: 14.2.1997 / 16:13:03 / cg"
 ! !
 
+
 !SequenceableCollection methodsFor:'searching'!
 
 detect:aBlock startingAt:startIndex
@@ -7602,6 +7625,20 @@
     "Modified: 21.8.1997 / 18:32:11 / cg"
 !
 
+sortByApplying:aBlock
+    "Sort my contents inplace based on the value of what aBlock returns for each element.
+     Similar to, but even more flexible than sortBySelector."
+
+    ^ self sort:[:a :b | (aBlock value:a) < (aBlock value:b)]
+
+    "
+     replace all uses of sort as in:
+        ... sort:[:a :b | a foo < b foo]
+     by:
+        ... sortByApplying:[:each | each foo]
+    "
+!
+
 sortBySelector:aSelector
     "Sort my contents inplace based on the value of what aSelector returns when sent to my
      elements. Sorting by a selector is so common, that its worth a separate utility"
@@ -7705,6 +7742,7 @@
     "Modified: 21.8.1997 / 18:30:49 / cg"
 ! !
 
+
 !SequenceableCollection methodsFor:'testing'!
 
 includesKey:anIndex
@@ -7732,11 +7770,11 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.289 2009-10-28 15:40:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.290 2010-01-20 09:55:32 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.289 2009-10-28 15:40:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.290 2010-01-20 09:55:32 cg Exp $'
 ! !
 
 SequenceableCollection initialize!