251 |
251 |
252 !Interval methodsFor:'enumerating'! |
252 !Interval methodsFor:'enumerating'! |
253 |
253 |
254 collect:aBlock |
254 collect:aBlock |
255 "evaluate the argument, aBlock for every element in the collection |
255 "evaluate the argument, aBlock for every element in the collection |
256 and return a collection of the results - Redefined since SeqColl |
256 and return a collection of the results. |
257 accesses the receiver via at:, which is slow for intervals" |
257 Redefined since SeqColl accesses the receiver via at:, which is slow for intervals" |
258 |
258 |
259 |newCollection| |
259 |newCollection| |
260 |
260 |
261 (start == 1 and:[step == 1]) ifTrue:[ |
261 (start == 1 and:[step == 1]) ifTrue:[ |
262 newCollection := Array new:(self size). |
262 newCollection := Array new:(self size). |
272 ^ newCollection |
272 ^ newCollection |
273 |
273 |
274 " |
274 " |
275 (1 to:20) collect:[:i | i*i] |
275 (1 to:20) collect:[:i | i*i] |
276 " |
276 " |
|
277 |
|
278 "Modified: / 22-10-2008 / 12:47:52 / cg" |
277 ! |
279 ! |
278 |
280 |
279 do:aBlock |
281 do:aBlock |
280 "evaluate the argument, aBlock for every element in the |
282 "evaluate the argument, aBlock for every element in the receiver-interval. |
281 receiver-interval. |
283 Redefined since SeqColl accesses the receiver with at:, which is slow for intervals." |
282 Redefined since SeqColl accesses the receiver with at:, which is |
|
283 slow for intervals." |
|
284 |
284 |
285 |aValue iter| |
285 |aValue iter| |
286 |
286 |
287 aValue := start. |
287 aValue := start. |
288 aValue isInteger ifTrue:[ |
288 aValue isInteger ifTrue:[ |
320 1e7 to:1e7+1 by:0.25 do:[:v | Transcript showCR:v] |
320 1e7 to:1e7+1 by:0.25 do:[:v | Transcript showCR:v] |
321 1.0 to:2.0 by:0.25 do:[:v | Transcript showCR:v] |
321 1.0 to:2.0 by:0.25 do:[:v | Transcript showCR:v] |
322 2.0 to:1.0 by:-0.25 do:[:v | Transcript showCR:v] |
322 2.0 to:1.0 by:-0.25 do:[:v | Transcript showCR:v] |
323 $a to:$z do:[:v | Transcript showCR:v] |
323 $a to:$z do:[:v | Transcript showCR:v] |
324 " |
324 " |
|
325 |
|
326 "Modified: / 22-10-2008 / 12:47:30 / cg" |
|
327 ! |
|
328 |
|
329 reverseDo:aBlock |
|
330 "evaluate the argument, aBlock for every element in the receiver-interval in |
|
331 reverse order. |
|
332 Redefined since SeqColl accesses the receiver with at:, which is slow for intervals." |
|
333 |
|
334 ^ self reversed do:aBlock |
|
335 |
|
336 " |
|
337 (1 to:10) do:[:el | Transcript showCR:el ]. |
|
338 (1 to:10) reverseDo:[:el | Transcript showCR:el ]. |
|
339 " |
|
340 |
|
341 "Modified: / 22-10-2008 / 12:49:28 / cg" |
325 ! |
342 ! |
326 |
343 |
327 select:aBlock |
344 select:aBlock |
328 "evaluate the argument, aBlock for every element in the collection |
345 "evaluate the argument, aBlock for every element in the collection |
329 and return a collection of all elements for which the block return |
346 and return a collection of all elements for which the block return true. |
330 true. Redefined since SeqColl accesses the receiver with at:, which is |
347 Redefined since SeqColl accesses the receiver with at:, which is slow for intervals." |
331 slow for intervals." |
|
332 |
348 |
333 |newColl| |
349 |newColl| |
334 |
350 |
335 newColl := self species new:(self size). |
351 newColl := self species new:(self size). |
336 self do:[:each | |
352 self do:[:each | |