Idea for a possibly better Collection occurrencesOf method.

Zulq Alam me at zulq.net
Tue Sep 12 00:11:29 UTC 2006


Raymond W. Lucke IV wrote:

> It seems to me that not using inject there might be reinventing the 
> wheel. Please excuse my ignorance if I'm incorrect here, I'm trying to 
> learn Smalltalk and get involved. Any ideas?

Is duplication really a problem in this case? I don't think so. Since 
you do, I'm curious what you think the risks are?

I do think it could be more readable though.

occurrencesOf: anObject
   "Answer how many of the receiver's elements are equal to anObject."

   ^ self count: [:each | each = anObject]

Thanks,
Zulq.



More information about the Squeak-dev mailing list