Collection.st
changeset 6547 86e092527dd1
parent 6511 0ca4f36b16ca
child 6555 e871e228b92f
equal deleted inserted replaced
6546:9cada8214da7 6547:86e092527dd1
  1669      a sequenceable collection (i.e. implements numeric key access)."
  1669      a sequenceable collection (i.e. implements numeric key access)."
  1670 
  1670 
  1671     |index  "{ Class: SmallInteger }" 
  1671     |index  "{ Class: SmallInteger }" 
  1672      newCollection|
  1672      newCollection|
  1673 
  1673 
  1674     newCollection := self species new.
  1674     newCollection := self speciesForAdding new.
       
  1675 
  1675     index := 1.
  1676     index := 1.
  1676     aCollection isSequenceable ifFalse:[
  1677     aCollection isSequenceable ifFalse:[
  1677         self isSequenceable ifFalse:[
  1678         self isSequenceable ifFalse:[
       
  1679             "/ mhmh - could use two streams here...
  1678             ^ self error:'neither collection is sequenceable'.
  1680             ^ self error:'neither collection is sequenceable'.
  1679         ].
  1681         ].
  1680         aCollection do:[:element |
  1682         aCollection do:[:element |
  1681             newCollection add:(aTwoArgBlock value:(self at:index) 
  1683             newCollection add:(aTwoArgBlock value:(self at:index) 
  1682                                             value:element).
  1684                                             value:element).
  1687             newCollection add:(aTwoArgBlock value:element 
  1689             newCollection add:(aTwoArgBlock value:element 
  1688                                             value:(aCollection at:index)).
  1690                                             value:(aCollection at:index)).
  1689             index := index + 1
  1691             index := index + 1
  1690         ]
  1692         ]
  1691     ].
  1693     ].
  1692     ^ newCollection
  1694     ^ newCollection as:self species
  1693 
  1695 
  1694     "
  1696     "
  1695      (1 to:3) with:#(one two three) collect:[:num :sym | (num->sym)]
  1697      (1 to:3) with:#(one two three) collect:[:num :sym | (num->sym)] 
  1696      #(1 2 3) with:#(10 20 30) collect:[:x :y | (x@y)]
  1698      #(1 2 3) with:#(10 20 30) collect:[:x :y | (x@y)]
  1697     "
  1699     "
  1698 !
  1700 !
  1699 
  1701 
  1700 with:aCollection do:aTwoArgBlock
  1702 with:aCollection do:aTwoArgBlock
  2198     count := 0.
  2200     count := 0.
  2199     self do:[:element |
  2201     self do:[:element |
  2200         count := count + 1
  2202         count := count + 1
  2201     ].
  2203     ].
  2202     ^ count
  2204     ^ count
       
  2205 !
       
  2206 
       
  2207 speciesForAdding
       
  2208      "like species, but redefined for collections which cannot grow easily.
       
  2209       Used by functions which create a growing collection (see collect:with:, for example)"
       
  2210 
       
  2211     ^ self species
  2203 ! !
  2212 ! !
  2204 
  2213 
  2205 !Collection methodsFor:'testing'!
  2214 !Collection methodsFor:'testing'!
  2206 
  2215 
  2207 capacity
  2216 capacity
  2372 ! !
  2381 ! !
  2373 
  2382 
  2374 !Collection class methodsFor:'documentation'!
  2383 !Collection class methodsFor:'documentation'!
  2375 
  2384 
  2376 version
  2385 version
  2377     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.123 2002-05-02 08:46:49 cg Exp $'
  2386     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.124 2002-05-15 08:04:35 cg Exp $'
  2378 ! !
  2387 ! !
  2379 Collection initialize!
  2388 Collection initialize!