--- a/SequenceableCollection.st Fri Apr 28 14:40:44 2017 +0200
+++ b/SequenceableCollection.st Fri Apr 28 15:05:11 2017 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -6122,6 +6124,55 @@
"
!
+with:aCollection andDefault:defaultElement do:aTwoArgBlock
+ "evaluate the argument, aBlock for successive elements from
+ each the receiver and the argument, aCollection.
+ If the receiver has more elements than the argument, use defaultElement
+ for remaining evaluations.
+ The third argument, aTwoArgBlock must be a two-argument block.
+ This method fails if neither the receiver nor aCollection is
+ a sequenceable collection (i.e. implements numeric key access)"
+
+ |index "{ Class: SmallInteger }"
+ sz "{ Class: SmallInteger }"|
+
+ index := 1.
+ sz := self size.
+
+ "aCollection may be non-sequenceable, but we are"
+ aCollection do:[:eachElement |
+ index >= sz ifTrue:[
+ ^ self.
+ ].
+ aTwoArgBlock value:(self at:index) value:eachElement.
+ index := index + 1.
+ ].
+
+ "I have more elements than aCollection"
+ index to:sz do:[:i|
+ aTwoArgBlock value:(self at:index) value:defaultElement.
+ ].
+
+
+ "
+ #(1 2 3) with:#(one two) andDefault:99 do:[:num :sym |
+ Transcript showCR:(num->sym)
+ ]
+
+ #() with:#(one two) andDefault:99 do:[:num :sym |
+ Transcript showCR:(num->sym)
+ ]
+
+ 'this example does not really make sense'
+ #(1 2 3) with:#(one two) asSet andDefault:99 do:[:num :sym |
+ Transcript showCR:(num->sym)
+ ]
+ "
+
+ "Created: / 28-04-2017 / 12:13:34 / stefan"
+ "Modified: / 28-04-2017 / 14:56:40 / stefan"
+!
+
with:aSequenceableCollection do:aTwoArgBlock
"evaluate the argument, aBlock for successive elements from
each the receiver and the argument, aSequenceableCollection.