> For the complete documentation index, see [llms.txt](https://mandober.gitbook.io/math-debrief/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mandober.gitbook.io/math-debrief/450-category-theory/10-morphisms/hylomorphism.md).

# Hylomorphism

<https://en.wikipedia.org/wiki/Hylomorphism\\_(computer\\_science)>

A *hylomorphism* is the composition of an anamorphism followed by a catamorphism. In FP, it is used for deforestation.

A hylomorphism is a recursive function, corresponding to the composition of an *anamorphism* (which first builds a set of results; also known as unfolding) followed by a *catamorphism* (which then folds these results into a final return value).

Fusion of these two recursive computations into a single recursive pattern then avoids building the intermediate data structure, which is an example of *deforestation*, a program optimization strategy.

A related type of function is a *metamorphism*, which is a catamorphism followed by an anamorphism.
