[Pharo-project] Issue 3235 in pharo: better bag sum

pharo at googlecode.com pharo at googlecode.com
Thu Nov 11 22:40:20 CET 2010


Updates:
	Status: FixedWaitingToBePharoed

Comment #2 on issue 3235 by stephane.ducasse: better bag sum
http://code.google.com/p/pharo/issues/detail?id=3235

This is strange in pharo there is no sum in Bag just in Collection

Collection>>sum
	"This is implemented using a variant of the normal inject:into: pattern.
	The reason for this is that it is not known whether we're in the normal
	number line, i.e. whether 0 is a good initial value for the sum.
	Consider a collection of measurement objects, 0 would be the unitless
	value and would not be appropriate to add with the unit-ed objects."
	| sum sample |
	sample := self anyOne.
	sum := self inject: sample into: [:accum :each | accum + each].
	^ sum - sample





More information about the Pharo-project mailing list