Skip to contents

Applies decorators to f left-to-right so that decorate(f, d1, d2) is equivalent to d2(d1(f)) and reads outside-in. Each decorator must be a unary function function(g) -> function. For decorators with configuration, wrap them in a closure or use the native pipe directly (which is the recommended idiom).

Usage

decorate(f, ...)

Arguments

f

A function to decorate.

...

Decorators — each a unary function taking f and returning a wrapped function.

Value

The decorated function.

Examples

# \donttest{
add1 <- function(x) x + 1
g <- decorate(
  add1,
  function(fn) with_retry(fn, max_tries = 2, backoff = 0),
  function(fn) with_timing(fn, .threshold = Inf)
)
g(41)
#> [1] 42
# }