Common enough to include it?

Andreas Raab andreas.raab at gmx.de
Tue Jan 22 17:15:29 UTC 2008


Both patterns effectively exist:

   (1 to: 3) collect: #printString

Cheers,
   - Andreas

Sebastian Sastre wrote:
> Hi there,
> 
> 	I've found a couple of simple but nice conveniences in collections:
> 
> 	A) To be able to do things like:
> 	
> 		persons collectAspect: #surname
> 
> collectAspect: aSymbol
> 	"Collects the element's answer to aSymbol"
> 	^ self collect:[:each| each perform: aSymbol]
> 
> 	B) To be able to do things like:
> 
> 		1 to: 12 collect:[:i| (Month nameOfMonth: i) asString ]
> 
> to: stop collect: aBlock 
> 	"Evaluate aBlock and adds it's answer to results 
> 	for each element of the interval (self to: stop by: 1)."
> 	| nextValue results |
> 	nextValue _ self.
> 	results := OrderedCollection new.
> 	[nextValue <= stop]
> 		whileTrue: 
> 			[results add: (aBlock value: nextValue).
> 			nextValue _ nextValue + 1].
> 	^ results 
> 
> 	Maybe they are universal enough to include in base?
> 
> 	cheers,
> 	
> Sebastian Sastre
> PS: I'm proposing to use this #collectAspect: in the very same way of #pluck
> as you can found it in Prototype enumerable, a kind of collection
> abstraction for javascript.
> 
> 
> 




More information about the Squeak-dev mailing list