Collection.st
changeset 24299 cc2dd3c923f4
parent 24256 6dfccbe099d3
child 24385 dd84e4dfb5cc
--- a/Collection.st	Sat Jun 08 16:50:56 2019 +0200
+++ b/Collection.st	Sat Jun 08 17:16:03 2019 +0200
@@ -579,6 +579,29 @@
     "
 !
 
+at:index add:anObject
+    "assuming that the receiver is an indexed collection of collections,
+     retrieve the collection at index, and add anObject to it.
+     Raise an error, of there is no collection at that index (or the index is invalid).
+     Typically used with dictionaries of sets."
+
+    (self at:index) add:anObject
+
+    "
+     (Dictionary new 
+        at:'one' put:Set new;
+        at:'two' put:Set new;
+        yourself)
+            at:'one' add:1;
+            at:'two' add:2;
+            at:'one' add:11;
+            at:'two' add:22;
+            yourself.
+    "
+
+    "Created: / 08-06-2019 / 16:59:26 / Claus Gittinger"
+!
+
 at:aKey ifAbsent:absentBlock
     "return the element at aKey if valid.
      If the key is not present, return the result of evaluating
@@ -600,6 +623,30 @@
     "Modified (comment): / 17-12-2018 / 17:33:06 / Claus Gittinger"
 !
 
+at:index ifAbsentPut:initializerValue add:anObject
+    "assuming that the receiver is an indexed collection of collections,
+     retrieve the collection at index, and add anObject to it.
+     If there is no collection at that index put the value of initializerValue there
+     and add to that.
+     Typically used with dictionaries of sets."
+
+    (self at:index ifAbsentPut:initializerValue) add:anObject
+
+    "
+     (Dictionary new 
+        at:'one' put:Set new;
+        at:'two' put:Set new;
+        yourself)
+            at:'one' add:1;
+            at:'two' add:2;
+            at:'one' add:11;
+            at:'two' add:22;
+            yourself.
+    "
+
+    "Created: / 08-06-2019 / 17:12:12 / Claus Gittinger"
+!
+
 at:aKey ifNilOrAbsentPut:valueBlock
     "try to fetch the element at aKey. If either the key is invalid (as in a Dictionary)
      or there is no element stored under that key (as in an Array), set the element