Collection.st
branchjv
changeset 19042 b81f2c85df7d
parent 19011 84c9f9410b1a
parent 19038 db10ee454719
child 19225 9e8abf62f932
--- a/Collection.st	Sat Jan 16 06:58:29 2016 +0100
+++ b/Collection.st	Sun Jan 17 06:49:17 2016 +0100
@@ -275,7 +275,6 @@
     ^ self newWithSize:n
 ! !
 
-
 !Collection class methodsFor:'Signal constants'!
 
 emptyCollectionSignal
@@ -337,8 +336,6 @@
     ^ self == Collection
 ! !
 
-
-
 !Collection methodsFor:'Compatibility-ANSI'!
 
 identityIncludes:anObject
@@ -530,7 +527,6 @@
     "Created: / 22-10-2008 / 21:29:27 / cg"
 ! !
 
-
 !Collection methodsFor:'accessing'!
 
 anElement
@@ -610,6 +606,13 @@
     "Modified: / 20.5.1998 / 14:50:46 / cg"
 !
 
+decrementAt:aKey 
+    "remove 1 from the count stored under aKey.
+     If not yet present, assume 0 as initial counter value."
+
+    self incrementAt:aKey by:-1
+!
+
 fifth
     "return the fifth element of the collection.
      For unordered collections, this simply returns the fifth
@@ -709,6 +712,20 @@
     "
 !
 
+incrementAt:aKey 
+    "add 1 to the count stored under aKey.
+     If not yet present, assume 0 as initial counter value."
+
+    self incrementAt:aKey by:1
+!
+
+incrementAt:aKey by:count
+    "add count to the count stored under aKey.
+     If not yet present, assume 0 as initial counter value."
+    
+    self at:aKey put:(self at:aKey ifAbsent:[0])+count.
+!
+
 keysSorted
     "return the keys as a sorted sequenceable collection.
      Some collections (which keep their keys already sorted) may
@@ -3037,6 +3054,7 @@
     ^ nextValue
 
     "
+     (1 to:10) fold:[:sum :el| sum + el]
      (1 to:15) fold:[:x :y| '(', x printString, '+', y printString, ')']
      (1 to:15) reduce:[:x :y| '(', x printString, '+', y printString, ')']
      #('if' 'it' 'is' 'to' 'be' 'it' 'is' 'up' 'to' 'me') fold: [:a :b | a, ' ', b]
@@ -4034,24 +4052,6 @@
 ! !
 
 
-!Collection methodsFor:'operations'!
-
-decrementAt:aKey
-    "decrement the value at aKey by one"
-
-    self at:aKey put:(self at:aKey) - 1.
-
-    "Modified: / 18-03-2011 / 10:32:04 / cg"
-!
-
-incrementAt:aKey
-    "increment the value at aKey by one"
-
-    self at:aKey put:(self at:aKey) + 1.
-
-    "Modified: / 18-03-2011 / 10:31:57 / cg"
-! !
-
 !Collection methodsFor:'printing & storing'!
 
 displayOn:aGCOrStream
@@ -5807,7 +5807,6 @@
     ^ aVisitor visitCollection:self with:aParameter
 ! !
 
-
 !Collection class methodsFor:'documentation'!
 
 version