strict_curry: Perform strict currying of a function

Description Usage Arguments Value Examples

Description

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.

Usage

1
2
3
fun %<!% arg

Curry(fun)

Arguments

fun

A function to be turned into a curried function.

arg

A value to be used when calling the curried function

Value

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
testfun <- function(x, y, z) {
  x + y + z
}
curriedfun <- Curry(testfun)
curriedfun(1)(2)(3)

# Using the operator
testfun %<!% 1 %<!% 2 %<!% 3

# The strict operator is only required for the first call
testfun %<!% 1 %<% 2 %<% 3

thomasp85/curry documentation built on May 31, 2019, 11:12 a.m.