itakewhile: Iterator that returns elements while a predicate function...

Description Usage Arguments Value Examples

Description

Constructs an iterator that returns elements from an iterable object as long as the given predicate function returns TRUE.

Usage

1
itakewhile(predicate, object)

Arguments

predicate

a function that determines whether an element is TRUE or FALSE. The function is assumed to take only one argument.

object

an iterable object

Value

iterator object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Filters out numbers exceeding 5
not_too_large <- function(x) {
  x <= 5
}
it <- itakewhile(not_too_large, 1:100)
unlist(as.list(it)) == 1:5

# Same approach but uses an anonymous function
it2 <- itakewhile(function(x) x <= 10, seq(2, 100, by=2))
unlist(as.list(it2)) == c(2, 4, 6, 8, 10)

itertools2 documentation built on May 2, 2019, 3:37 p.m.