#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Sat, 25 May 2019 11:18:10 +0200
changeset 24146 7f198b02b945
parent 24145 60971523ce2f
child 24147 a6e10cfad9c7
#FEATURE by cg class: Collection added: #keysAndValuesDo:separatedBy:
Collection.st
--- a/Collection.st	Sat May 25 09:08:47 2019 +0200
+++ b/Collection.st	Sat May 25 11:18:10 2019 +0200
@@ -3668,6 +3668,37 @@
     ^ self errorNotKeyed
 !
 
+keysAndValuesDo:aTwoArgBlock separatedBy:sepBlock
+    "evaluate the argument, aBlock for every element in the collection,
+     passing both index/key and element as arguments.
+     Between elements, evaluate aBlock (but not before the first)."
+
+    |first|
+
+    first := true.
+    self keysAndValuesDo:[:k :v |
+        first ifFalse:[
+            sepBlock value.
+        ].
+        first := false.
+        aTwoArgBlock value:k value:v
+    ].
+
+    "
+     |d|
+     d := OrderedDictionary withKeysAndValues:#('one' 1 'two' 2 'three' 3 'four' 4).
+     
+     d keysAndValuesDo:[:k :v | Transcript showCR:'%1 -> %2' with:k with:v]
+       separatedBy:[Transcript showCR:'===='].
+     
+     Transcript cr;cr.
+     d keysAndValuesDo:[:k :v | Transcript showCR:'%1 -> %2' with:k with:v].
+    "
+
+    "Created: / 25-05-2019 / 10:07:54 / Claus Gittinger"
+    "Modified (comment): / 25-05-2019 / 11:17:34 / Claus Gittinger"
+!
+
 keysAndValuesReverseDo:aTwoArgBlock
     "evaluate the argument, aBlock in reverse order for every element in the collection,
      passing both index and element as arguments.