R/utils.R

Defines functions accumulate

## accumulate a la Abelson and Sussman.

accumulate <- function(f, init, x, right = TRUE) {
  if (length(x) == 0) {
    return(init)
  }
  f <- match.fun(f)
  if (right) {
    f(x[[1]], Recall(f, init, x[-1], right = TRUE))
  } else {
    Recall(f, f(init, x[[1]]), x[-1], right = FALSE)
  }
}

Try the polynom package in your browser

Any scripts or data that you put into this service are public.

polynom documentation built on April 11, 2022, 9:05 a.m.