Skip to content

fold

Summary

Reduce a list.

Tip

This function is curried.

Description

Reduce a list xs by applying f first to the initial value and the first element of the list, then to value returned by the previous reduction and subsequent element of the list.

Examples

Product of a list

1
2
3
4
const product = fold(mult, 1);

product([1,2,3,4]);
//=> 24

Parameters

Name Type Description
f function Binary function.
init ? Initial value
xs ? A list (either an array or an object)

Return

?