fp::nestvals
-- repeated
composition returning intermediate valuesfp::nestvals
(f,n)
returns a function which
applies the function f
n
-fold repeatedly to
ist argument and returns the intermediate results.
fp::nestvals(f, n)
f |
- | function |
n |
- | nonnegative integer |
A function.
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.fp::nestvals
returns the function
x -> [x, f(x), f(f(x)),... f(f(...f(x)...))]
[ _fnest(f,i) $i=0..n
]
, but more efficient.Apply f
3 times nested to
x
:
>> fp::nestvals(f, 3)(x)
[x, f(x), f(f(x)), f(f(f(x)))]
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]