Common enough to include it?
ssastre at seaswork.com
Tue Jan 22 16:42:16 UTC 2008
I've found a couple of simple but nice conveniences in collections:
A) To be able to do things like:
persons collectAspect: #surname
"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]
[results add: (aBlock value: nextValue).
nextValue _ nextValue + 1].
Maybe they are universal enough to include in base?
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
More information about the Squeak-dev