Idea for a possibly better Collection occurrencesOf method.
Raymond W. Lucke IV
smalltalk at raylucke.com
Tue Sep 12 00:29:56 UTC 2006
Hi Zulq,
I didn't see any risks either way, I guess my thought was that it
would be more elegant to not use the temporary variables. Your way is
even more elegant. Is there any performance downside to using count
or inject instead of do with a temporary variable? It would seem to
me that it would be more efficient the way you just described as well.
Ray
On Sep 11, 2006, at 5:11 PM, Zulq Alam wrote:
> 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.
>
>
> !DSPAM:4505fab4278191804284693!
>
More information about the Squeak-dev
mailing list
|