Common enough to include it?
Sebastian Sastre
ssastre at seaswork.com
Tue Jan 22 16:42:16 UTC 2008
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
|