Description Usage Arguments Details Examples
The limit of the generator refers to the output series, not the underlying state. This approach tends to be more intuitive, especially when the state is a vector (like the Fibonacci numbers).
1 | limit(.generator, .limit)
|
.generator |
A function with the class |
.limit |
A predicate function, returning |
When the limiting function returns TRUE
, a generator is considered
exhausted. Additional calls to an exhausted generator return an error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # A typical case
counter <- generator(0, function (state) state + 1)
limited <- counter %>% limit(~ state < 4)
limited %>% take(3)
# Returns an error
## Not run: limited()
# Fibonacci numbers
fib <- generator(c(0, 1),
~ c(state[2], sum(state)),
~ state[1])
limited <- fib %>% limit(~ state < 5)
limited %>% take(4)
# Returns an error
## Not run: limited()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.