Skip to content

Esta página también está en español.

Léela en español

このページは日本語でも読めます。

日本語で読む

本页也有简体中文版本。

阅读简体中文版本

fold function

Combine the elements of a list from the left with a function, starting from a value.

How to write it

fold(f, start, list)

f
A function of two arguments. Takes a function.
start
The first value. Takes an expression.
list
The elements to combine. Takes a list.

Examples

  • fold⁡(plus⁡,0,[1,2,3])=6\displaystyle \operatorname{fold}(\operatorname{plus}, 0, \left[ 1, 2, 3 \right]) = 6
    fold(plus, 0, [1, 2, 3])

    In the solver, fold(plus, 0, [1, 2, 3]) gives 6.

    Open in the solver
  • fold_list

    The steps of fold: every partial result, starting from the first value.

  • flatten

    Nested lists flattened into one list.

  • head

    The head of an expression: the name of the function it is a call of.

  • first

    The first element of a list.

  • intersection

    The elements that are in every one of some lists.

  • drop

    A list without its first elements.