Description Usage Arguments See Also Examples
Generate iterations of a generator up to its limit, reducing the values using a binary function.
1 |
.generator |
A function with the class |
.FUN |
A binary fold function to reduce the generator to a single value |
... |
Additional arguments to .FUN |
.start |
The starting value for the reduction |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Sum of numbers from 1 to 10
counter <- generator(0, function (state) state + 1)
counter %>%
limit(~ state <= 10) %>%
foldc(`+`)
# Version of Project Euler 2: Sum of even Fibonacci numbers
fib <- generator(c(0, 1),
~ c(state[2], sum(state)),
~ state[1])
fib %>%
keep(~ state %% 2 == 0) %>%
limit(~ state < 400) %>%
foldc(`+`)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.