[Pharo-project] Issue 3641 in pharo: possible new implementation of reduce:

pharo at googlecode.com pharo at googlecode.com
Tue Feb 1 07:41:23 CET 2011

Status: Accepted
Owner: stephane... at gmail.com
Labels: Milestone-1.3

New issue 3641 by stephane... at gmail.com: possible new implementation of  

there 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  
        For sequenceable collections the elements will be used in order, for  
        collections the order is unspecified."

         | first nextValue |
         first := true.
         self do: [ :each |
                         ifTrue: [ nextValue := each. first := false ]
                         ifFalse: [ nextValue := binaryBlock value:  
nextValue value: each ] ].
         first ifTrue: [ self errorEmptyCollection ].
         ^nextValue! !

More information about the Pharo-project mailing list