vadr
vadr copied to clipboard
Somewhat faster currying
Moving the makeActiveBinding out of the inner call speeds this up at least for repeated calls:
curr3 <- function(f, ...) {
if (missing(...)) {
f
} else {
stored_dots <- list(NULL, get("..."))
selector <- 0
del("...")
makeActiveBinding("...",
function() stored_dots[[selector <<- selector+1]],
environment())
f0 <- function() {
selector <<- 0
f(...)
}
f1 <- function() {
selector <<- 0
f(..., ...)
}
function(...) {
if (missing(...)) {
f0()
} else {
stored_dots[1] <<- list(get("..."))
f1()
}
}
}
}