fp::fold
-- create function which
iterates over sequencesfp::fold
(f,e)
returns a function which
repeatedly applies f
to sequences of arguments, using
e
as starting value.
fp::fold(f <, e...>)
f |
- | function |
e |
- | object used as starting value |
A function.
fp::fold
returns a function which repeatedly applies
f
to sequences of arguments, where the expressions
e...
are used as starting values.fp::fold
returns the function
which is defined by
(x[1],x[2],...x[m]) -> f(x[m],...f(x[2],f(x[1],e[1],...e[n]))...)for any positive integer m. If the argument sequnce is void (i.e. m=0) the function simply returns the sequence (e[1],...e[n]).
>> fp::fold(f, x)(y1, y2, y3)
f(y3, f(y2, f(y1, x)))
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)
{{}, {b}, {a}, {c}, {b, c}, {a, b}, {a, c}, {a, b, c}}