yield {peruse}R Documentation

Increment an Iterator and Return the Next Value(s)

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

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

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)

[Package peruse version 0.3.1 Index]