Fold (aka Reduce) is Functional Form of Loop (2025)

By Xah Lee. Date: .

What is the Purpose of Fold (aka reduce) Function

Usually, we think Reduce is useful only for niche purposes, such as total a list of numbers.

Actually, reduce is a general way for any possible algorithm you can write with loop, but in a functional style.

It simply pass the state of last iteration to the function.

fold, reduce