consume: Consume an generator, taking all iterations up to a limit

Description Usage Arguments Details Examples

View source: R/consume.R

Description

consume is a special version of take, with additional controls to help the user. It produces the same output and warns the user (through guess) if the number of iterations taken is insufficient to reach the limit.

Usage

1
consume(.generator, .guess, .simplify)

Arguments

.generator

A function with the class generator

.guess

An approximate number of steps until the limit

.simplify

If FALSE return a list, else return an array

Details

It needs to be preceded by a limit to a generator. The function checks whether a generator is limited, but other errors are possible if the limit occurs earlier in the chain of wrappers.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# A typical example
counter <- generator(0, function (state) state + 1)
counter %>% limit(~ state < 20) %>% consume

# Should throw a warning
## Not run: 
counter %>%
  reset %>%
  limit(~ state < 20) %>%
  consume(10)

## End(Not run)

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