Learn R Programming

curry (version 0.1.1)

tail_curry: Curry a function from the end

Description

The tail_curry function and the %-<%< code=""> operator performs currying on a function by partially applying the last argument, returning a function that accepts all but the last arguments of the former function. If the last argument is ... the curried argument will be interpreted as the last named argument. If the only argument to the function 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).

Usage

fun %-<% arg<="" div="">
tail_curry(fun, arg)

Arguments

fun
A function to be curried from the end. Can be any function (normal, already (tail_)curried, primitives).
arg
The value that should be applied to the last argument.

Value

A function with the same arguments as fun except for the last named argument, unless the only one is ... in which case it will be retained.

See Also

Other partials: curry, partial

Examples

Run this code
# Equivalent to tail_curry(`/`, 5)
divide_by_5 <- `/` %-<% 5
divide_by_5(10)

no_factors <- data.frame %-<% FALSE
no_factors(x = letters[1:5])

Run the code above in your browser using DataLab