Array.st
changeset 1123 4e79c452592f
parent 1083 fadaedfa28f8
child 1133 961f2b095c22
equal deleted inserted replaced
1122:251ea6ec6c61 1123:4e79c452592f
   815     ^ super reverseDo:aBlock
   815     ^ super reverseDo:aBlock
   816 !
   816 !
   817 
   817 
   818 traverse:aBlock
   818 traverse:aBlock
   819     "Evaluate aBlock for every element that is not an Array, 
   819     "Evaluate aBlock for every element that is not an Array, 
   820      and traverse Arrays.
   820      and recursively traverse Arrays.
   821      Implemented here to support better search for selectors in
   821      Implemented here to support better search for selectors in
   822      literal arrays - might be a good idea to move it up in the collection
   822      literal arrays - might be a good idea to move it up in the collection
   823      hierarchy, since this may be a useful method for other collections
   823      hierarchy, since this may be a useful method for other collections
   824      as well."
   824      as well."
   825 
   825 
   826     self do: [:el |
   826     self do: [:el |
   827 	el isArray
   827         el isArray
   828 	    ifTrue: [el traverse: aBlock]
   828             ifTrue: [el traverse: aBlock]
   829 	    ifFalse: [aBlock value: el]]
   829             ifFalse: [aBlock value: el]]
   830 
   830 
   831     "
   831     "
   832      example: flattening an Array:
   832      example: flattening an Array:
   833 
   833 
   834      |s|
   834      |s|
   835 
   835 
   836      s := WriteStream on:Array new.
   836      s := WriteStream on:Array new.
   837      #(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | s nextPut:el].
   837      #(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | s nextPut:el].
   838      s contents 
   838      s contents 
   839     "
   839     "
       
   840     "
       
   841      example: deep search
       
   842 
       
   843      #(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | 
       
   844         el == 10 ifTrue:[Transcript showCr:'found']
       
   845      ]
       
   846     "
       
   847 
       
   848     "Modified: 26.3.1996 / 17:08:10 / cg"
   840 ! !
   849 ! !
   841 
   850 
   842 !Array methodsFor:'filling & replacing'!
   851 !Array methodsFor:'filling & replacing'!
   843 
   852 
   844 from:index1 to:index2 put:anObject
   853 from:index1 to:index2 put:anObject
  1370 ! !
  1379 ! !
  1371 
  1380 
  1372 !Array class methodsFor:'documentation'!
  1381 !Array class methodsFor:'documentation'!
  1373 
  1382 
  1374 version
  1383 version
  1375 ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.57 1996-03-07 14:15:04 cg Exp $'! !
  1384 ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.58 1996-03-26 16:08:34 cg Exp $'! !