vadr icon indicating copy to clipboard operation
vadr copied to clipboard

Somewhat faster currying

Open crowding opened this issue 12 years ago • 0 comments

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()
      }
    }
  }
}

crowding avatar Jan 03 '14 13:01 crowding