Interval.st
changeset 11270 a616ba9b7f81
parent 11266 4f9e413eba36
child 11409 82874ed12ab4
equal deleted inserted replaced
11269:f45a4a2cd7ab 11270:a616ba9b7f81
   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 |
   339     ^ newColl
   355     ^ newColl
   340 
   356 
   341     "
   357     "
   342      (1 to:20) select:[:i | i even]
   358      (1 to:20) select:[:i | i even]
   343     "
   359     "
       
   360 
       
   361     "Modified: / 22-10-2008 / 12:47:41 / cg"
   344 ! !
   362 ! !
   345 
   363 
   346 !Interval methodsFor:'printing & storing'!
   364 !Interval methodsFor:'printing & storing'!
   347 
   365 
   348 displayString
   366 displayString
   598 ! !
   616 ! !
   599 
   617 
   600 !Interval class methodsFor:'documentation'!
   618 !Interval class methodsFor:'documentation'!
   601 
   619 
   602 version
   620 version
   603     ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.45 2008-10-22 07:17:55 cg Exp $'
   621     ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.46 2008-10-22 10:49:27 cg Exp $'
   604 ! !
   622 ! !