SequenceableCollection.st
changeset 24613 6ef497bafadb
parent 24600 b5981fd97fba
child 24662 7cbf62ded916
equal deleted inserted replaced
24612:1ac50ebe401a 24613:6ef497bafadb
  5018 
  5018 
  5019 from:startIndex do:aBlock
  5019 from:startIndex do:aBlock
  5020     "evaluate the argument, aBlock for the elements starting with the
  5020     "evaluate the argument, aBlock for the elements starting with the
  5021      element at startIndex to the end."
  5021      element at startIndex to the end."
  5022 
  5022 
  5023     ^ self from:startIndex to:self size do:aBlock
  5023     self from:startIndex to:self size do:aBlock
  5024 
  5024 
  5025     "
  5025     "
  5026      #(one two three four five six)
  5026      #(one two three four five six)
  5027 	from:3
  5027         from:3
  5028 	do:[:element | Transcript showCR:element]
  5028         do:[:element | Transcript showCR:element]
  5029     "
  5029     "
  5030 !
  5030 !
  5031 
  5031 
  5032 from:startIndex doWithExit:aBlock
  5032 from:startIndex doWithExit:aBlock
  5033     "evaluate the argument, aBlock for the elements starting with the
  5033     "evaluate the argument, aBlock for the elements starting with the
  5034      element at startIndex to the end. Passes an additional exitBlock as second
  5034      element at startIndex to the end. Passes an additional exitBlock as second
  5035      argument, which can be used to exit the loop early."
  5035      argument, which can be used to exit the loop early.
       
  5036      For convenience, return the exit argument if there was an early exit,
       
  5037      and nil, if there was not."
  5036 
  5038 
  5037     ^ self from:startIndex to:self size doWithExit:aBlock
  5039     ^ self from:startIndex to:self size doWithExit:aBlock
  5038 
  5040 
  5039     "
  5041     "
  5040      #(one two three four five six)
  5042      #(one two three four five six)
  5041         from:3
  5043         from:3
  5042         doWithExit:[:element :exit | 
  5044         doWithExit:[:element :exit | 
  5043             Transcript showCR:element.
  5045             Transcript showCR:element.
  5044             element = 'four' ifTrue:[ exit value:nil ]
  5046             element = 'four' ifTrue:[ exit value:999 ]
  5045         ]
  5047         ]      
  5046     "
  5048     "
  5047 
  5049 
  5048     "Created: / 28-07-2013 / 22:37:28 / cg"
  5050     "Created: / 28-07-2013 / 22:37:28 / cg"
  5049 !
  5051 !
  5050 
  5052 
  5051 from:startIndex doWithIndex:aTwoArgBlock
  5053 from:startIndex doWithIndex:aTwoArgBlock
  5052     "evaluate the argument, aTwoArgBlock for the elements starting with the
  5054     "evaluate the argument, aTwoArgBlock for the elements starting with the
  5053      element at startIndex to the end,
  5055      element at startIndex to the end,
  5054      passing both the element and its index as argument."
  5056      passing both the element and its index as argument."
  5055 
  5057 
  5056     ^ self from:startIndex to:self size doWithIndex:aTwoArgBlock
  5058     self from:startIndex to:self size doWithIndex:aTwoArgBlock
  5057 
  5059 
  5058     "
  5060     "
  5059      #(one two three four five six)
  5061      #(one two three four five six)
  5060         from:3
  5062         from:3
  5061         doWithIndex:[:element :idx | Transcript showCR:idx->element]
  5063         doWithIndex:[:element :idx | Transcript showCR:idx->element]
  5066 
  5068 
  5067 from:startIndex keysAndValuesDo:aBlock
  5069 from:startIndex keysAndValuesDo:aBlock
  5068     "evaluate the argument, aBlock for the elements and indices starting with the
  5070     "evaluate the argument, aBlock for the elements and indices starting with the
  5069      element at startIndex to the end."
  5071      element at startIndex to the end."
  5070 
  5072 
  5071     ^ self from:startIndex to:self size keysAndValuesDo:aBlock
  5073     self from:startIndex to:self size keysAndValuesDo:aBlock
  5072 
  5074 
  5073     "
  5075     "
  5074      #(one two three four five six)
  5076      #(one two three four five six)
  5075 	from:3
  5077         from:3
  5076 	keysAndValuesDo:[:element :idx | Transcript showCR:(idx -> element) ]
  5078         keysAndValuesDo:[:element :idx | Transcript showCR:(idx -> element) ]
  5077     "
  5079     "
  5078 !
  5080 !
  5079 
  5081 
  5080 from:index1 to:index2 by:stepArg do:aBlock
  5082 from:index1 to:index2 by:stepArg do:aBlock
  5081     "evaluate the argument, aBlock for the elements with index index1 to index2 stepping by step in the collection"
  5083     "evaluate the argument, aBlock for the elements with index index1 to index2 stepping by step in the collection"
  5169 !
  5171 !
  5170 
  5172 
  5171 from:index1 to:index2 doWithExit:aBlock
  5173 from:index1 to:index2 doWithExit:aBlock
  5172     "evaluate the argument, aBlock for the elements with index index1 to
  5174     "evaluate the argument, aBlock for the elements with index index1 to
  5173      index2 in the collection. Pass an additional exitBlock as second argument,
  5175      index2 in the collection. Pass an additional exitBlock as second argument,
  5174      which can be used to exit the loop early."
  5176      which can be used to exit the loop early.
       
  5177      For convenience, return the exit argument if there was an early exit,
       
  5178      and nil, if there was not."
  5175 
  5179 
  5176     |exitBlock|
  5180     |exitBlock|
  5177 
  5181 
  5178     exitBlock := [:value | ^ value].
  5182     exitBlock := [:value | ^ value].
  5179     ^ self from:index1 to:index2 do:[:el |
  5183     self from:index1 to:index2 do:[:el |
  5180         aBlock value:el value:exitBlock
  5184         aBlock value:el value:exitBlock
  5181     ].
  5185     ].
       
  5186     ^ nil
  5182 
  5187 
  5183     "
  5188     "
  5184      #(one two three four five six)
  5189      #(one two three four five six)
  5185         from:3 to:5 doWithExit:[:element :exit | 
  5190         from:3 to:5 doWithExit:[:element :exit | 
  5186             Transcript showCR:element.
  5191             Transcript showCR:element.
  5628      CONFUSION ATTACK: 
  5633      CONFUSION ATTACK: 
  5629         this is different from pairsDo:.
  5634         this is different from pairsDo:.
  5630         but the Squeak-pairsDo: does the same as our pairWiseDo: 
  5635         but the Squeak-pairsDo: does the same as our pairWiseDo: 
  5631         (sigh: but we were first, so they should have adapted...)"
  5636         (sigh: but we were first, so they should have adapted...)"
  5632 
  5637 
  5633     ^ self inGroupsOf:2 do:aTwoArgBlock
  5638     self inGroupsOf:2 do:aTwoArgBlock
  5634 
  5639 
  5635     "
  5640     "
  5636      #(1 one 2 two 3 three 4 four 5 five 6 six)
  5641      #(1 one 2 two 3 three 4 four 5 five 6 six)
  5637          pairWiseDo:[:num :sym | Transcript show:num; show:' is: '; showCR:sym]
  5642          pairWiseDo:[:num :sym | Transcript show:num; show:' is: '; showCR:sym]
  5638 
  5643