Search notes:

Common first class function: fold

There are two versions of the fold operator: a right-fold and a left-fold. The fold operator takes as its arguments a so called zero-value (Z), a function (f) and a list.
f takes as its arguments two values and returns one value.
Fold-right:
fold_right(Z, f, [v1, v2, v3]) == f(v1, f(v2, f(v3, Z)))
Fold-left:
fold_left(Z, f, [v1, v2, v3]) == f(f(f(Z, v1), v2), v3)

Misc

The fold operator has its origins in recursion theory (Kleene, 1952).

See also

Functional programming

Index