Bienlein:

There is the nice old Smalltalk-80 inject:into: method in the Collection class:

| list sum |
list := OrderedCollection new add: 1; add: 2; add: 3; yourself.
sum := list inject: 0 into: [ :a :b | a + b ].
Transcript cr; show: sum.  "prints 6"

A little more general ;-). The Scala guys have also cloned it where it is called foldLeft.

In D there's std.algorithm.reduce.
I think Scala guys have copied something older than Smalltalk.

Bye,
bearophile

Reply via email to