Documentation

# `fp`::`fold`

Create function which iterates over sequences

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

```fp::fold(`f`, <`e, …`>)
```

## Description

`fp::fold` returns a function which repeatedly applies `f` to sequences of arguments, where the expressions `e...` are used as starting values.

Thus, given the function f and the starting values e1, …, en, `fp::fold` returns the function which is defined by for any positive integer m. If the argument sequence is void (i.e. m = 0) the function simply returns the sequence (e1, …, en).

## Examples

### Example 1

A call to `fp::fold` returns a function, which accepts an arbitrary number of arguments:

`fp::fold(f, x)(y1, y2, y3)`
` `

### Example 2

The function `pset` returns the power set of the set given by its arguments:

```addelem := (x,y) -> y union map(y, _union, {x}): pset := fp::fold(addelem, {{}}): pset(a,b,c)```
` `

## Parameters

 `f` Function `e` Object used as starting value

## Return Values

Function.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos