> For the complete documentation index, see [llms.txt](https://haskell.hpmeducation.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haskell.hpmeducation.com/recursion/folds.md).

# Folds

A **fold** or a **folding function** is a higher-order function that processes a data structure (e.g. a list) in some order and builds a return value along the way. Therefore, a fold needs three things to work - **a function that combines the elements, a starting value, and the data structure** where the elements are stored.

There are two basic folding functions defined in the Haskell Prelude, `foldr` and `foldl`. The difference between them is the order in which they apply the combining function to the elements.
