Find head/tail that all satisfies a predicate.
head_while(.x, .p, ...) tail_while(.x, .p, ...)
.x | A list or atomic vector. |
---|---|
.p | A single predicate function, a formula describing such a
predicate function, or a logical vector of the same length as |
... | Additional arguments passed on to the mapped function. |
A vector the same type as .x
.
pos <- function(x) x >= 0 head_while(5:-5, pos)#> [1] 5 4 3 2 1 0#> [1] -1 -2 -3 -4 -5big <- function(x) x > 100 head_while(0:10, big)#> integer(0)tail_while(0:10, big)#> integer(0)