REBOL [
Title: "Accumulate"
Date: 3-Jul-2002/20:40
Name: Accumulate
Version: 1.0.1
File: %Accumulate.r
Author: "Andrew Martin"
Purpose: {Cumulates values in a block together,
by successively applying the function
to each value in Series.
}
Email: Al.Bri@xtra.co.nz
Web: http://valley.150m.com
Category: [math 1]
Acknowledgements: [
"Ladislav Mecir"
"Carl Sassenrath"
]
Example: [
Accumulate 0 [1 2 3 4 5] :+
]
]
Accumulate: func [
{Cumulates values in a block together,
by successively applying the function
to each value in Series.}
[catch]
Accumulator [any-type!]
Series [series!]
F [any-function!]
"Function that takes two parameters, Accumulator and Item."
] [
throw-on-error [
foreach Item Series [
Accumulator: F Accumulator :Item
]
:Accumulator
]
]