ifilter: Create a filtering iterator

Description Usage Arguments Examples

Description

The ifilter and ifilterfalse functions create iterators that return a subset of the values of the specified iterable. ifilter returns the values for which the pred function returns TRUE, and ifilterfalse returns the values for which the pred function returns FALSE.

Usage

1
2
ifilter(pred, iterable)
ifilterfalse(pred, iterable)

Arguments

pred

A function that takes one argument and returns TRUE or FALSE.

iterable

The iterable to iterate over.

Examples

1
2
3
4
5
# Return the odd numbers between 1 and 10
as.list(ifilter(function(x) x %% 2 == 1, icount(10)))

# Return the even numbers between 1 and 10
as.list(ifilterfalse(function(x) x %% 2 == 1, icount(10)))

Example output

Loading required package: iterators
[[1]]
[1] 1

[[2]]
[1] 3

[[3]]
[1] 5

[[4]]
[1] 7

[[5]]
[1] 9

[[1]]
[1] 2

[[2]]
[1] 4

[[3]]
[1] 6

[[4]]
[1] 8

[[5]]
[1] 10

itertools documentation built on May 2, 2019, 2:26 p.m.