Collection.st
branchjv
changeset 18040 a11a12546f23
parent 18037 4cf874da38c9
parent 14966 ad42577cb895
child 18043 03660093fe98
--- a/Collection.st	Mon Mar 25 23:04:02 2013 +0000
+++ b/Collection.st	Wed Mar 27 12:24:15 2013 +0000
@@ -327,6 +327,7 @@
     ^ self == Collection
 ! !
 
+
 !Collection methodsFor:'*ST2JS-compatibility'!
 
 inlineDo: aBlock
@@ -506,6 +507,23 @@
     "Created: / 22-10-2008 / 21:29:27 / cg"
 !
 
+withIndexCollect:aTwoArgBlock
+    "same as keysAndValuesCollect:, but with argument order reversed"
+
+    |newCollection|
+
+    newCollection := OrderedCollection new.
+    self keysAndValuesDo:[:key :value |
+        newCollection add:(aTwoArgBlock value:value value:key)
+    ].
+    ^ newCollection
+
+    "
+     #(one two three) withIndexCollect:[:sym :num | (num->sym)] 
+     #(10 20 30) withIndexCollect:[:n :i | n*i ]  
+    "
+!
+
 withIndexDo:aTwoArgBlock 
     "evaluate the argument, aBlock for every element in the collection,
      passing both element and index as arguments."
@@ -1979,6 +1997,17 @@
     ^ (self copyEmpty:size) grow:size
 !
 
+copyWith: additionalElement 
+    "Return a copy of the dictionary that is 1 bigger than the receiver and 
+     includes the argument, additionalElement, at the end."
+
+    | newColl |
+
+    newColl := self copy.
+    newColl add: additionalElement.
+    ^ newColl
+!
+
 postCopyFrom:original
     "sent to a freshly copied object to give it a chance to adjust things.
      Notice, that for Sets/Dicts etc. a rehash is not needed, since the copy
@@ -4574,11 +4603,11 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.293 2013-03-21 08:32:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.295 2013-03-26 16:09:26 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.293 2013-03-21 08:32:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.295 2013-03-26 16:09:26 cg Exp $'
 ! !