Status: Accepted
Owner:
[hidden email]
Labels: Milestone-1.3
New issue 3641 by
[hidden email]: possible new implementation of
reduce:
http://code.google.com/p/pharo/issues/detail?id=3641there is already a version of reduce: made by lukas and I would like to
know the difference with this one (proposed by eliot because squeak did not
got reduce:)
if people can comment on speed... and whatever it would be good.
Collection>>reduce: binaryBlock
"Apply the argument, binaryBlock cumulatively to the elements of the
receiver.
For sequenceable collections the elements will be used in order, for
unordered
collections the order is unspecified."
| first nextValue |
first := true.
self do: [ :each |
first
ifTrue: [ nextValue := each. first := false ]
ifFalse: [ nextValue := binaryBlock value:
nextValue value: each ] ].
first ifTrue: [ self errorEmptyCollection ].
^nextValue! !