yields: Increment an Iterator and Return the Next Value(s)

Description Usage Arguments Value Examples

Description

Finds the value of the next iteration(s) of an Iterator object and increments the Iterator to the next value(s). yield_more() repeats yield_next() a specified number of times. Refer to the number of the current iteration in yield_more() with .iter.

Usage

1
2
3
yield_next(iter)

yield_more(iter, more = 1L)

Arguments

iter

An Iterator object

more

How many values to yield

Value

An object of whatever type result evaluates to from the Iterator, or a vector of that type in the case of yield_more(iter, more > 1L).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
primes <- 2:10000 %>%
         that_for_all(range(2, .x)) %>%
         we_have(~.x %% .y != 0, "Iterator")

sequence <- yield_more(primes, 100)

# use `.iter` to reference the current iteration
rwd <- Iterator({
        set.seed(seeds[.iter])
        n <- n + sample(c(-1L, 1L), size = 1L, prob = c(0.25, 0.75))
       },
       initial = list(n = 0, seeds = 1:100),
       yield = n)

yield_more(rwd, 100)

jacgoldsm/pytools documentation built on March 17, 2021, 6:36 a.m.