Description Usage Arguments Value Examples
The curry
function and %<%
operator does not perform currying
in the strictest sense since it is really "just" a partial application of the
first argument. Strictly speaking currying transforms a function into a
function taking a single argument and returning a new function accepting a
new argument as long as the original function has arguments left. Once all
arguments has been consumed by function calls it evaluates the original call
and returns the result. Strict currying has less applicability in R as it
cannot work with functions containing '...' in its argument list as it will
never reach the end of the argument list and thus never evaluate the call.
Strict currying is still provided here for completeness. The Curry()
function turns a function into a curried function reducing the ariety to one.
The %<!%
operator both transforms the function into a curried one
and calls it once with the first argument. Once a function is curried it is
still possible to use %<%
, %-<%
, and %><%
though
they all performs the same operation as the function does only accept a
single argument. As with the other functions in the curry
package,
argument names and defaults are retained when performing strict currying.
Calling a curried function without providing a value for it will call it with
the default or set the argument to missing.
1 2 3 | fun %<!% arg
Curry(fun)
|
fun |
A function to be turned into a curried function. |
arg |
A value to be used when calling the curried function |
A function accepting a single argument and returing either a new function accepting a single argument, or the result of the function call if all arguments have been provided.
1 2 3 4 5 6 7 8 9 10 11 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.