[Newbies] How to shorten a method (using inject: into: ?)
Randal L. Schwartz
merlyn at stonehenge.com
Tue Jul 22 16:24:25 UTC 2008
>>>>> "cdrick" == cdrick <cdrick65 at gmail.com> writes:
cdrick> Always choose the most readable (before optimizing) and to me, the
cdrick> following is much more readable:
cdrick> mTotal := (testSets collect: [:each | each maternalCount]) sum.
cdrick> pTotal := (testSets collect: [:each | each paternalCount]) sum.
Well, the #detectSum: solution is even cleaner. :)
mTotal := testSets detectSum: [:each | each maternalCount].
It's just a horribly named method, which is why I didn't find it at first.
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
More information about the Beginners