icompress: Iterator that filters elements where corresponding selector...

Description Usage Arguments Details Value Examples

Description

Constructs an iterator that filters elements from iterable returning only those for which the corresponding element from selectors is TRUE.

Usage

1
icompress(object, selectors)

Arguments

object

an iterable object

selectors

an iterable that determines whether the corresponding element in object is returned.

Details

The iterator stops when either object or selectors has been exhausted.

Value

iterator object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Filters out odd numbers and retains only even numbers
n <- 10
selectors <- rep(c(FALSE, TRUE), n)
it <- icompress(seq_len(n), selectors)
as.list(it)

# Similar idea here but anonymous function is used to filter out even
# numbers
n <- 10
it2 <- icompress(seq_len(10), rep(c(TRUE, FALSE), n))
as.list(it2)

it3 <- icompress(letters, letters %in% c('a', 'e', 'i', 'o', 'u'))
as.list(it3)

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