Description Usage Arguments Value Note See Also Examples
The curry
function and the %<%
operator performs currying on
a function by partially applying the first argument, returning a function
that accepts all but the first arguments of the former function. If the first
argument is ...
the curried argument will be interpreted as part of
the ellipsis and the ellipsis will be retained in the returned function. It
is thus possible to curry functions comtaining ellipis arguments to infinity
(though not adviced).
1 2 3 | fun %<% arg
curry(fun, arg)
|
fun |
A function to be curried. Can be any function (normal, already curried, primitives). |
arg |
The value that should be applied to the first argument. |
A function with the same arguments as fun
except for the
first, unless the first is ...
in which case it will be retained.
Multiple currying does not result in multiple nested calls, so while the first currying adds a layer around the curried function, potentially adding a very small performance hit, currying multiple times will not add to this effect.
Other partials: partial
,
tail_curry
1 2 3 4 5 6 7 | # Equivalent to curry(`+`, 5)
add_5 <- `+` %<% 5
add_5(10)
# ellipsis are retained when currying
bind_5 <- cbind %<% 5
bind_5(1:10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.