# fold 函数

从左侧开始，用函数把列表的元素逐步结合，并从某个值出发。

## 怎么写

### fold(f, start, list)

**f**

接受两个参数的函数。接受一个函数。

**start**

初始值。接受一个表达式。

**list**

要结合的元素。接受一个列表。

## 示例

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

  `fold(plus, 0, [1, 2, 3])`

  在求解器中，`fold(plus, 0, [1, 2, 3])` 的结果是 `6`。

  [在求解器中打开](https://zh.hilberon.com/?q=fold%28plus%2C%200%2C%20%5B1%2C%202%2C%203%5D%29)

## 相关函数

- [fold_list](https://zh.hilberon.com/library/fold_list)

  fold 的各个步骤：从初始值开始的每一个中间结果。
- [flatten](https://zh.hilberon.com/library/flatten)

  把嵌套列表展平为一个列表。
- [head](https://zh.hilberon.com/library/head)

  表达式的头部：它所调用的函数的名称。
- [first](https://zh.hilberon.com/library/first)

  列表的第一个元素。
- [intersection](https://zh.hilberon.com/library/intersection)

  同时属于若干个列表的所有元素。
- [drop](https://zh.hilberon.com/library/drop)

  去掉开头若干元素后的列表。

---
Source: https://zh.hilberon.com/library/fold
