SequenceableCollection.st
changeset 8853 dab477726542
parent 8851 3910c013402b
child 8859 42a82dadb147
equal deleted inserted replaced
8852:9f5984eff2c2 8853:dab477726542
  3528      #(1 one 2 two 3 three 4 four 5 five 6 six) 
  3528      #(1 one 2 two 3 three 4 four 5 five 6 six) 
  3529          inGroupsOf:2 do:[:num :sym | Transcript show:num; show:' is: '; showCR:sym]
  3529          inGroupsOf:2 do:[:num :sym | Transcript show:num; show:' is: '; showCR:sym]
  3530 
  3530 
  3531      #( 1 2 3 4 5    6 7 8 9 10   11 12 13 14 15   16 17 18 19 20 )
  3531      #( 1 2 3 4 5    6 7 8 9 10   11 12 13 14 15   16 17 18 19 20 )
  3532          inGroupsOf:5 do:[:a :b :c :d :e | Transcript show:a;space;show:b;space;show:c;space;show:d;space;showCR:e]
  3532          inGroupsOf:5 do:[:a :b :c :d :e | Transcript show:a;space;show:b;space;show:c;space;show:d;space;showCR:e]
       
  3533     "
       
  3534 !
       
  3535 
       
  3536 keysAndValuesCollect:aTwoArgBlock
       
  3537     "evaluate the argument, aBlock for every element in the collection,
       
  3538      passing both index and element as arguments.
       
  3539      Collect the returned values and return them."
       
  3540 
       
  3541     |newCollection|
       
  3542 
       
  3543     newCollection := self copyEmpty.
       
  3544     self keysAndValuesDo:[:k :v |
       
  3545         newCollection add:(aTwoArgBlock value:k value:v).
       
  3546     ].
       
  3547     ^ newCollection
       
  3548 
       
  3549     "
       
  3550      #(one two three four five six) 
       
  3551         keysAndValuesCollect:[:key :element | 
       
  3552                             key even ifTrue:element ifFalse:[element asUppercase]]
       
  3553 
       
  3554 
       
  3555      |d|
       
  3556 
       
  3557      d := Dictionary new.
       
  3558      d at:'a' put:'A'.
       
  3559      d at:'b' put:'B'.
       
  3560      d at:'c' put:'C'.
       
  3561      d at:'d' put:'D'.
       
  3562      d at:'e' put:'E'.
       
  3563      d keysAndValuesCollect:[:key :element | 
       
  3564                             key first codePoint even 
       
  3565                                 ifTrue:element 
       
  3566                                 ifFalse:[element asLowercase]]   
  3533     "
  3567     "
  3534 !
  3568 !
  3535 
  3569 
  3536 keysAndValuesDo:aTwoArgBlock
  3570 keysAndValuesDo:aTwoArgBlock
  3537     "evaluate the argument, aBlock for every element in the collection,
  3571     "evaluate the argument, aBlock for every element in the collection,
  6809 ! !
  6843 ! !
  6810 
  6844 
  6811 !SequenceableCollection class methodsFor:'documentation'!
  6845 !SequenceableCollection class methodsFor:'documentation'!
  6812 
  6846 
  6813 version
  6847 version
  6814     ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.222 2005-04-19 09:05:46 cg Exp $'
  6848     ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.223 2005-04-19 10:04:48 cg Exp $'
  6815 ! !
  6849 ! !
  6816 
  6850 
  6817 SequenceableCollection initialize!
  6851 SequenceableCollection initialize!