Collection.st
changeset 19010 9747c5331e87
parent 18961 2047840e1521
child 19011 84c9f9410b1a
child 19037 69fd31f9c1c0
equal deleted inserted replaced
19008:e74b041ed377 19010:9747c5331e87
   334      True is returned for Collection here; false for subclasses.
   334      True is returned for Collection here; false for subclasses.
   335      Abstract subclasses must redefine again."
   335      Abstract subclasses must redefine again."
   336 
   336 
   337     ^ self == Collection
   337     ^ self == Collection
   338 ! !
   338 ! !
       
   339 
       
   340 
   339 
   341 
   340 !Collection methodsFor:'Compatibility-ANSI'!
   342 !Collection methodsFor:'Compatibility-ANSI'!
   341 
   343 
   342 identityIncludes:anObject
   344 identityIncludes:anObject
   343     "return true, if the argument, anObject is in the collection.
   345     "return true, if the argument, anObject is in the collection.
  3470 !
  3472 !
  3471 
  3473 
  3472 select:selectBlock thenCollect:collectBlock as:aCollectionClass
  3474 select:selectBlock thenCollect:collectBlock as:aCollectionClass
  3473     "return a new collection with all elements from the receiver, for which
  3475     "return a new collection with all elements from the receiver, for which
  3474      the argument selectBlock evaluates to true.
  3476      the argument selectBlock evaluates to true.
  3475      Process the elements throgh collectBlock before adding.
  3477      Process the elements through collectBlock before adding.
  3476      Returns the same as if three separate collect+select+as: messages were sent,
  3478      Returns the same as if three separate collect+select+as: messages were sent,
  3477      but avoids the creation of intermediate collections, so this is nicer for
  3479      but avoids the creation of intermediate collections, so this is nicer for
  3478      big collections."
  3480      big collections."
  3479 
  3481 
  3480     |newCollection|
  3482     |newCollection|
  3493     "Created: / 07-08-2010 / 16:26:15 / cg"
  3495     "Created: / 07-08-2010 / 16:26:15 / cg"
  3494 !
  3496 !
  3495 
  3497 
  3496 select:selectBlock thenDo:doBlock
  3498 select:selectBlock thenDo:doBlock
  3497     "combination of select followed by do
  3499     "combination of select followed by do
  3498      Avoids the creation of intermediate garbage"
  3500      The same as if two separate select:+do: messages were sent,
       
  3501      but avoids the creation of intermediate collections, 
       
  3502      so this is nicer for big collections."
  3499 
  3503 
  3500     self do:[:eachElement |
  3504     self do:[:eachElement |
  3501         (selectBlock value:eachElement) ifTrue:[
  3505         (selectBlock value:eachElement) ifTrue:[
  3502             doBlock value:eachElement
  3506             doBlock value:eachElement
  3503         ]
  3507         ]