Fold left reduce function javascript

broken image
broken image

Folds are in a sense dual to unfolds, which take a seed value and apply a function corecursively to decide how to progressively construct a corecursive data structure, whereas a fold recursively breaks that structure down, replacing it with the results of applying a combining function at each node on its terminal values and the recursive results (catamorphism, versus anamorphism of unfolds). The fold then proceeds to combine elements of the data structure's hierarchy, using the function in a systematic way.

broken image

Typically, a fold is presented with a combining function, a top node of a data structure, and possibly some default values to be used under certain conditions.

broken image

broken image