fp::curry -- curry a n-ary
function
Introductionfp::curry(f) returns the higher-order
function x -> (y -> f(x,y)).
Call(s)fp::curry(f <, n>)
Parametersf |
- | n-ary function |
n |
- | nonnegative integer |
ReturnsA unary higher-order function.
Detailsfp::curry returns the curried version of the
n-ary function f. If no arity n
is given, then the function is assumend to be binary.n is smaller than 2 then f is
returned. Otherwise, given a n-ary function f,
fp::curry returns the function
x[1] -> (x[2] -> ... (x[n] -> f(x[1],...,x[n]))...)
Example
1Create curried versions of binary and 3-nary functions:
>> cf := fp::curry(f): cf(x)(y)
f(x, y)
>> cg := fp::curry(g, 3): cg(x)(y)(z)
g(x, y, z)
Example
2A curried version of _plus may be used to
create a function which increments its argument by 1:
>> inc := fp::curry(_plus)(1): inc(x)
x + 1