-
Notifications
You must be signed in to change notification settings - Fork 1
Fold
laforge49 edited this page Jul 31, 2011
·
4 revisions
Sometimes you just want to perform a simple operation across the values of a sequence. Fold is a good choice when you can use it, as it is fast and easy to use.
case class Fold[V](seed: V, f: (V, V) => V)
Just send a Fold message to a sequence and it returns a result of type V. It calls f(seed, value) on the each value in the sequence to calculate a revised seed--which at the end is the returned result. Testing this is a one liner.
println(Future(new Range(1,4), Fold(0, (a: Int, b: Int) => a + b)))
Output.
6