i_keepwhile {iterors} | R Documentation |
Iterator that returns elements while a predicate function returns TRUE
Description
Constructs an iterator that returns elements from an iterable object
as long as the given predicate
function returns TRUE
.
Usage
i_keepwhile(object, predicate, ...)
Arguments
object |
an iterable object |
predicate |
a function that determines whether an element is |
... |
passed along to |
Value
iterator object
Examples
# Filters out numbers exceeding 5
not_too_large <- function(x) {
x <= 5
}
it <- i_keepwhile(1:100, not_too_large)
unlist(as.list(it)) == 1:5
# Same approach but uses an anonymous function
it2 <- i_keepwhile(seq(2, 100, by=2), function(x) x <= 10)
unlist(as.list(it2)) == c(2, 4, 6, 8, 10)
[Package iterors version 1.0 Index]