Previous Page Next Page Contents

fp::fold -- create function which iterates over sequences

Introduction

fp::fold(f,e) returns a function which repeatedly applies f to sequences of arguments, using e as starting value.

Call(s)

fp::fold(f <, e...>)

Parameters

f - function
e - object used as starting value

Returns

A function.

Details

Example 1

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

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)
          {{}, {b}, {a}, {c}, {b, c}, {a, b}, {a, c}, {a, b, c}}

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000