parse_function_name <- function(f) {
deparse(substitute(f))
}
flatten_list <- function(x) {
if (is_flat_list(x)) {
x
} else {
flatten_list(
unlist(x, recursive = FALSE)
)
}
}
map <- function(fn) {
function(x) {
result <- vector(typeof(x), length(x))
vec_names <- names(x)
for (i in seq_along(x)) {
result[[i]] <- fn(x[[i]])
}
names(result) <- vec_names
result
}
}
reduce <- function(fn, init) {
function(x) {
acc <- init
for (i in seq_along(x)) {
acc <- fn(acc, x[[i]])
}
acc
}
}
compose <- function(...) {
\(x) {
Reduce(
function(res, fn) fn(res),
rev(list(...)),
x
)
}
}
n_args <- function(fn) {
length(
suppressWarnings({
formals(args(fn))
})
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.