tail_curry {curry}R Documentation

Curry a function from the end

Description

The tail_curry function and the %-<% 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

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.

Note

Multiple tail_currying does not result in multiple nested calls, so while the first tail_currying adds a layer around the curried function, potentially adding a very small performance hit, tail_currying multiple times will not add to this effect.

See Also

Other partials: curry, partial

Examples

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

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


[Package curry version 0.1.1 Index]