Iterator that drops elements until the predicate function returns FALSE
Source:R/idropwhile.R
i_dropwhile.Rd
Constructs an iterator that drops elements from the iterable object
as
long as the predicate
function is true; afterwards, every element of
iterable
object is returned.
Arguments
- object
an iterable object
- predicate
a function that determines whether an element is
TRUE
orFALSE
. The function is assumed to take only one argument.- ...
Further arguments forwarded to iteror.
Value
An iteror object.
Details
Because the iterator does not return any elements until the predicate
first becomes false, there may have a lengthy start-up time before elements
are returned.
Examples
# Filters out numbers exceeding 3
not_too_large <- function(x) {
x <= 3
}
it <- i_dropwhile(1:8, not_too_large)
as.list(it)
#> [[1]]
#> [1] 4
#>
#> [[2]]
#> [1] 5
#>
#> [[3]]
#> [1] 6
#>
#> [[4]]
#> [1] 7
#>
#> [[5]]
#> [1] 8
#>
# Same approach but uses an anonymous function
it2 <- i_dropwhile(seq(2, 20, by=2), function(x) x <= 10)
as.list(it2)
#> [[1]]
#> [1] 12
#>
#> [[2]]
#> [1] 14
#>
#> [[3]]
#> [1] 16
#>
#> [[4]]
#> [1] 18
#>
#> [[5]]
#> [1] 20
#>