R/utils-keepers.R

Defines functions compact discard is_empty

# NOTE!!!
# This requires map_lgl() which requries map()

is_empty <- function(x) length(x) == 0

# keep <- function(.x, .p, ...) {
#   .x[map_lgl(.x, .p, ...)]
# }

discard <- function(.x, .p, ...) {
  .x[!map_lgl(.x, .p, ...)]
}

compact <- function(.x, .p=identity) {
  discard(.x, function(x) is_empty(.p(x)))
}

Try the starter package in your browser

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

starter documentation built on Oct. 15, 2024, 5:06 p.m.