final classFoldState[X, -I, +O] extends Serializable
A FoldState defines a left fold with a "hidden" accumulator type. It is exposed so
library authors can run Folds over their own sequence types.
The fold can be executed correctly according to the properties of "add" and your traversed
data structure. For example, the "add" function of a monoidal fold will be associative. A
FoldState is valid for only one iteration because the accumulator (seeded by "start" may be
mutable.
The three components of a fold are
add: (X, I) => X - updates and returns internal state for every input I
start: X - the initial state
end: X => O - transforms internal state to a final result
Folding over Seq(x, y) would produce the result
end(add(add(start, x), y))
A FoldState defines a left fold with a "hidden" accumulator type. It is exposed so library authors can run Folds over their own sequence types.
The fold can be executed correctly according to the properties of "add" and your traversed data structure. For example, the "add" function of a monoidal fold will be associative. A FoldState is valid for only one iteration because the accumulator (seeded by "start" may be mutable.
The three components of a fold are add: (X, I) => X - updates and returns internal state for every input I start: X - the initial state end: X => O - transforms internal state to a final result
Folding over Seq(x, y) would produce the result end(add(add(start, x), y))