#FEATURE
authorClaus Gittinger <cg@exept.de>
Thu, 14 Jan 2016 19:37:48 +0100
changeset 19026 23b3c4c6c9e7
parent 19025 f35582ce8389
child 19027 d1a18f4568a8
child 19028 483e4c9cdaf7
#FEATURE class: SequenceableCollection added: #with:with:do: comment/format in: #with:do: changed: #with:doWithIndex:
SequenceableCollection.st
--- a/SequenceableCollection.st	Thu Jan 14 17:08:34 2016 +0100
+++ b/SequenceableCollection.st	Thu Jan 14 19:37:48 2016 +0100
@@ -398,7 +398,6 @@
     ^ self == SequenceableCollection
 ! !
 
-
 !SequenceableCollection methodsFor:'Compatibility-Squeak'!
 
 allButFirst
@@ -711,7 +710,6 @@
     ^ self replaceFrom:start to:stop with:anArray startingAt:repStart
 ! !
 
-
 !SequenceableCollection methodsFor:'accessing'!
 
 after:anObject
@@ -5865,7 +5863,7 @@
      each the receiver and the argument, aSequenceableCollection.
      The second argument, aBlock must be a two-argument block.
      The collection argument must implement access via a numeric key 
-     and (new!!) the sizes must be the same."
+     and the sizes must be the same (this is a new check!!)."
 
     |stop  "{ Class: SmallInteger }" |
 
@@ -5880,7 +5878,7 @@
 
     "
      #(one two three four five six)
-        with:(1 to:10)
+        with:(1 to:6)
         do:[:el1 :el2 | Transcript show:el1; space; showCR:el2]
     "
 
@@ -5892,11 +5890,15 @@
      each the receiver and the argument, aSequenceableCollection.
      aBlock must be a three-argument block, which get elements from either collection and
      the index as arguments.
-     The collection argument must implement access via a numeric key."
+     The collection argument must implement access via a numeric key.
+     and the sizes must be the same (this is a new check!!)."
 
     |stop  "{ Class: SmallInteger }" |
 
     stop := self size.
+    aSequenceableCollection size == stop ifFalse:[
+        NotEnoughElementsSignal raiseRequestErrorString:'collections must be of the same size'.
+    ].
     1 to:stop do:[:index |
         aThreeArgBlock 
             value:(self at:index) 
@@ -5912,6 +5914,37 @@
 
     "Created: / 05-07-2006 / 18:07:11 / fm"
     "Modified (comment): / 08-01-2012 / 17:18:59 / cg"
+!
+
+with:collection2 with:collection3 do:aThreeArgBlock
+    "evaluate the argument, aBlock for successive elements from
+     each the receiver and the collection arguments.
+     The last argument, aBlock must be a three-argument block.
+     The collection arguments must implement access via a numeric key 
+     and the sizes must be the same."
+
+    |stop  "{ Class: SmallInteger }" |
+
+    stop := self size.
+    (collection2 size == stop and:[collection3 size == stop])  ifFalse:[
+        NotEnoughElementsSignal raiseRequestErrorString:'collections must be of the same size'.
+    ].
+
+    1 to:stop do:[:index |
+        aThreeArgBlock 
+            value:(self at:index) 
+            value:(collection2 at:index)
+            value:(collection3 at:index).
+    ]
+
+    "
+     #(one two three four five six)
+        with:(1 to:6)
+        with:(100 to:600 by:100)
+        do:[:el1 :el2 :el3 | Transcript show:el1; space; show:el2; space; showCR:el3]
+    "
+
+    "Modified (Format): / 30-06-2011 / 17:39:59 / cg"
 ! !
 
 !SequenceableCollection methodsFor:'filling & replacing'!
@@ -7686,7 +7719,6 @@
     "Created: 14.2.1997 / 16:13:03 / cg"
 ! !
 
-
 !SequenceableCollection methodsFor:'searching'!
 
 detect:aBlock startingAt:startIndex