Programing Language: Fold vs Reduce

By Xah Lee. Date: . Last updated: .

fold vs reduce

in programing languages,

xah is correct.

Origin of the concept of fold or reduce

Why do some programing language have both fold and reduce and are different?

The reason fold and reduce diversified is because, its easier to have separate functions to deal with optional parameter of the init value, or special case of empty list. e.g. in fsharp, in guile scheme lisp. And in Cpp, it is far worse.

Typically, for those programing language that have separate fold and reduce, the reduce is the one that just takes a list, including if the list is empty, and no init value.

In Science of Terminology and Communication, Which Term is Better? Fold or Reduce?

What is the Relation Reduce to Parallel Computing

What about Google's Map Reduce? does it mean reduce is related to parallel computation?

What is commutative property and associative property

commutative property means

f(a,b) == f(b,a)

associative property means

f(f(a,b),c) == f(a,f(b,c))

what operations have commutative property and associative property?

example plus.

can be also written as

also, multiplication too.

most operation (aka function) are not commutative, and not associative property.

Xah discord argument about fold and reduce

fold reduce xah discord 2025-05-26 1
fold reduce xah discord 2025-05-26 1
fold reduce xah discord 2025-05-26 2
fold reduce xah discord 2025-05-26 2

fold, reduce