Skip to main content

List.fold

foldinitf

Documentation

Combines all the elements of the list, by iteratively applying the passed function with next elements of the list.

In general, the result of (Cons l0 <| Cons l1 <| ... <| Cons ln) . fold init f is the same as f (...(f (f init l0) l1)...) ln

Arguments

  • init: The initial value for the fold.
  • f: The binary function used to combine elements of the list.

Examples

In the following example, we'll compute the sum of all elements of a

list.

      import Standard.Examples

example_fold = Examples.list.fold 0 (+)