fp::fixargs -- create function
by fixing all but one argument
Introductionfp::fixargs(f,1,y) returns the function
x -> f(x,y).
Call(s)fp::fixargs(f, n <, e...>)
Parametersf |
- | function |
n |
- | positive integer defining free argument |
e |
- | object used as fixed argument |
ReturnsAn unary function.
Detailsfp::fixargs returns an unary function, defined by
fixing all but the n-th argument of the function
f to the values given by e....fp::fixargs returns the function
x -> f(e[1],...e[n-1],x,e[n],...e[m-1])
Example
1Fix the first and third argument of f to
x1 and x3:
>> fp::fixargs(f, 2, x1, x3)(y)
f(x1, y, x3)
Example
2Create a function which increments its argument by one:
>> inc := fp::fixargs(_plus, 1, 1): inc(x)
x + 1
Example
3Create a function which tests the identifier
x for a type:
>> type_of_x := fp::fixargs(testtype, 2, x): map([DOM_INT, DOM_IDENT], type_of_x)
[FALSE, TRUE]