Common enough to include it?

Bert Freudenberg bert at freudenbergs.de
Tue Jan 22 17:41:23 UTC 2008


They "accept" anything that understands #value:. There are different  
opinions about Symbol>>#value: being a good idea or not. It's  
certainly convenient.

- Bert -


On Jan 22, 2008, at 18:35 , Sebastian Sastre wrote:

> Oh great. I had the idea that they where accepting only blocks. Cool,
>
> 	cheers,
>
> Sebastian Sastre
>
>
>
>> -----Mensaje original-----
>> De: squeak-dev-bounces at lists.squeakfoundation.org
>> [mailto:squeak-dev-bounces at lists.squeakfoundation.org] En
>> nombre de Andreas Raab
>> Enviado el: Martes, 22 de Enero de 2008 15:15
>> Para: The general-purpose Squeak developers list
>> Asunto: Re: Common enough to include it?
>>
>> 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