Compose: Compose an arbitrary number of functions.

View source: R/functional.R

ComposeR Documentation

Compose an arbitrary number of functions.

Description

My Happy Hacking keyboard gave out during the writing of this procedure; moment of silence, please.

Usage

Compose(...)

Arguments

...

the functions to be composed

Details

Had to make this slightly more complex to handle the nullary case; also included a fast-path for the trivial case.

Value

A composed function

Examples

car <- function(list) list[[1]]
cdr <- function(list) list[2:length(list)]
cadr <- Compose(cdr, car)
stopifnot(cadr(c(1,2,3)) == 2)

functional documentation built on June 24, 2026, 9:08 a.m.