Collection.st
changeset 11412 46a2355bc640
parent 11385 c3d908e81ec7
child 11436 8b542c2a5a9d
equal deleted inserted replaced
11411:b2958949d9a4 11412:46a2355bc640
  1105     self do:[:each |
  1105     self do:[:each |
  1106         aDoubleArray at:index put:each asFloat.
  1106         aDoubleArray at:index put:each asFloat.
  1107         index := index + 1
  1107         index := index + 1
  1108     ].
  1108     ].
  1109     ^ aDoubleArray
  1109     ^ aDoubleArray
       
  1110 !
       
  1111 
       
  1112 asFlatOrderedCollection
       
  1113     |coll|
       
  1114 
       
  1115     coll := OrderedCollection new.
       
  1116     self flatDo:[:el | coll add:el].
       
  1117     ^ coll.
       
  1118 
       
  1119     "
       
  1120      #(
       
  1121         (1 2 3)
       
  1122         4 5
       
  1123         (6)
       
  1124         7
       
  1125         (8 (9 10) 11 12 (13 (14 (15) 16)))) asFlatOrderedCollection
       
  1126     "
  1110 !
  1127 !
  1111 
  1128 
  1112 asFloatArray
  1129 asFloatArray
  1113     "return a new FloatArray with the collections elements
  1130     "return a new FloatArray with the collections elements
  1114      (which must convert to floats)."
  1131      (which must convert to floats)."
  1843     "
  1860     "
  1844 
  1861 
  1845     "Modified: 18.4.1996 / 14:16:59 / cg"
  1862     "Modified: 18.4.1996 / 14:16:59 / cg"
  1846 !
  1863 !
  1847 
  1864 
       
  1865 flatDo:aBlock
       
  1866     "for each element of the collection, if its a scalar, evaluate aBlock for it;
       
  1867      otherwise, recursively invoke flatDo on the collection."
       
  1868 
       
  1869     self do:[:each |
       
  1870         (each isNonByteCollection) ifTrue:[
       
  1871             each flatDo:aBlock
       
  1872         ] ifFalse:[
       
  1873             aBlock value:each
       
  1874         ].
       
  1875     ].
       
  1876 
       
  1877     "
       
  1878      #(
       
  1879         (1 2 3)
       
  1880         4 5
       
  1881         (6)
       
  1882         7
       
  1883         (8 (9 10) 11 12 (13 (14 (15) 16)))) flatDo:[:el | Transcript showCR:el]
       
  1884     "
       
  1885 !
       
  1886 
  1848 inject:thisValue into:binaryBlock
  1887 inject:thisValue into:binaryBlock
  1849     "starting with thisValue for value, pass this value and each element
  1888     "starting with thisValue for value, pass this value and each element
  1850      to binaryBlock, replacing value with the result returned from the block
  1889      to binaryBlock, replacing value with the result returned from the block
  1851      in the next iteration."
  1890      in the next iteration."
  1852 
  1891 
  2324      The default returned here may be (and is) redefined in subclasses."
  2363      The default returned here may be (and is) redefined in subclasses."
  2325 
  2364 
  2326     ^ self size max:2
  2365     ^ self size max:2
  2327 ! !
  2366 ! !
  2328 
  2367 
       
  2368 
       
  2369 !Collection methodsFor:'operations'!
       
  2370 
       
  2371 decrementAt:aKey
       
  2372     self at:aKey put:(self at:aKey) - 1.
       
  2373 !
       
  2374 
       
  2375 incrementAt:aKey
       
  2376     self at:aKey put:(self at:aKey) + 1.
       
  2377 ! !
  2329 
  2378 
  2330 !Collection methodsFor:'printing & storing'!
  2379 !Collection methodsFor:'printing & storing'!
  2331 
  2380 
  2332 displayString
  2381 displayString
  2333     "return a printed representation of the receiver for display in inspectors etc."
  2382     "return a printed representation of the receiver for display in inspectors etc."
  3273 ! !
  3322 ! !
  3274 
  3323 
  3275 !Collection class methodsFor:'documentation'!
  3324 !Collection class methodsFor:'documentation'!
  3276 
  3325 
  3277 version
  3326 version
  3278     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.210 2008-12-02 17:10:42 stefan Exp $'
  3327     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.211 2008-12-15 14:08:00 cg Exp $'
  3279 ! !
  3328 ! !
  3280 
  3329 
  3281 Collection initialize!
  3330 Collection initialize!