keep: Filter a series by keeping results that fulfill a predicate

Description Usage Arguments Examples

View source: R/filter.R

Description

Filter a series by keeping results that fulfill a predicate

Usage

1
keep(.generator, .keep)

Arguments

.generator

A function with the class generator

.keep

A predicate function, returning TRUE or FALSE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Generate even numbers
counter <- generator(0, ~ state + 1)
counter %>%
  keep(~ state %% 3 == 0) %>% take(5)

# Combine a wrap and a counter
squares <- function(state) state ^ 2
counter %>%
  wrap(squares) %>%
  keep(~ state %% 3 == 0) %>%
  take(5)

michaelquinn32/generators documentation built on May 22, 2019, 9:52 p.m.