## `fp::nestvals` -- repeated composition returning intermediate values

#### Introduction

`fp::nestvals``(f,n)` returns a function which applies the function `f` `n`-fold repeatedly to ist argument and returns the intermediate results.

#### Call(s)

`fp::nestvals(f, n)`

#### Parameters

`f` | - | function
`n` | - | nonnegative integer

#### Returns

A function.

#### Related Functions

`_fconcat`, `_fnest`

#### Details

- `fp::nestvals` returns a function which applies the function `f` 0- to `n`-fold repeated to its arguments and returns these n+1 values as a list.
- Thus `fp::nestvals` returns the function

      x -> [x, f(x), f(f(x)),... f(f(...f(x)...))]

- The function returned is equivalent to `[ _fnest(f,i) $i=0..n ]`, but more efficient.

#### Example 1

Apply `f` 3 times nested to `x`:

    >> fp::nestvals(f, 3)(x)

                          [x, f(x), f(f(x)), f(f(f(x)))]

#### Example 2

Apply `cos` 4 times nested to `1.0` and return the result and intermediate values:

    >> fp::nestvals(cos, 4)(1.0)

           [1.0, 0.5403023059, 0.8575532159, 0.6542897905, 0.7934803588]

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000