6120 #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21) |
6122 #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21) |
6121 slicesOf:5 do:[:slice | Transcript showCR:slice] |
6123 slicesOf:5 do:[:slice | Transcript showCR:slice] |
6122 " |
6124 " |
6123 ! |
6125 ! |
6124 |
6126 |
|
6127 with:aCollection andDefault:defaultElement do:aTwoArgBlock |
|
6128 "evaluate the argument, aBlock for successive elements from |
|
6129 each the receiver and the argument, aCollection. |
|
6130 If the receiver has more elements than the argument, use defaultElement |
|
6131 for remaining evaluations. |
|
6132 The third argument, aTwoArgBlock must be a two-argument block. |
|
6133 This method fails if neither the receiver nor aCollection is |
|
6134 a sequenceable collection (i.e. implements numeric key access)" |
|
6135 |
|
6136 |index "{ Class: SmallInteger }" |
|
6137 sz "{ Class: SmallInteger }"| |
|
6138 |
|
6139 index := 1. |
|
6140 sz := self size. |
|
6141 |
|
6142 "aCollection may be non-sequenceable, but we are" |
|
6143 aCollection do:[:eachElement | |
|
6144 index >= sz ifTrue:[ |
|
6145 ^ self. |
|
6146 ]. |
|
6147 aTwoArgBlock value:(self at:index) value:eachElement. |
|
6148 index := index + 1. |
|
6149 ]. |
|
6150 |
|
6151 "I have more elements than aCollection" |
|
6152 index to:sz do:[:i| |
|
6153 aTwoArgBlock value:(self at:index) value:defaultElement. |
|
6154 ]. |
|
6155 |
|
6156 |
|
6157 " |
|
6158 #(1 2 3) with:#(one two) andDefault:99 do:[:num :sym | |
|
6159 Transcript showCR:(num->sym) |
|
6160 ] |
|
6161 |
|
6162 #() with:#(one two) andDefault:99 do:[:num :sym | |
|
6163 Transcript showCR:(num->sym) |
|
6164 ] |
|
6165 |
|
6166 'this example does not really make sense' |
|
6167 #(1 2 3) with:#(one two) asSet andDefault:99 do:[:num :sym | |
|
6168 Transcript showCR:(num->sym) |
|
6169 ] |
|
6170 " |
|
6171 |
|
6172 "Created: / 28-04-2017 / 12:13:34 / stefan" |
|
6173 "Modified: / 28-04-2017 / 14:56:40 / stefan" |
|
6174 ! |
|
6175 |
6125 with:aSequenceableCollection do:aTwoArgBlock |
6176 with:aSequenceableCollection do:aTwoArgBlock |
6126 "evaluate the argument, aBlock for successive elements from |
6177 "evaluate the argument, aBlock for successive elements from |
6127 each the receiver and the argument, aSequenceableCollection. |
6178 each the receiver and the argument, aSequenceableCollection. |
6128 The second argument, aBlock must be a two-argument block. |
6179 The second argument, aBlock must be a two-argument block. |
6129 The collection argument must implement access via a numeric key |
6180 The collection argument must implement access via a numeric key |