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


Search within the itertools package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.