Create a filtering iterator

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)))