The General Purpose of Fold/Reduce Function (2025)

By Xah Lee. Date: .

For advanced coders. Functional programing. The general purpose of 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.