recycle: Recycle a generator

Description Usage Arguments Examples

View source: R/limit.R

Description

Recycling is limiting with one major change. Instead of throwing an error when the generator is exhuasted, recycle resets the state of the generator to its starting value.

Usage

1
recycle(.generator, .limit)

Arguments

.generator

A function with the class generator

.limit

A predicate function, returning TRUE or FALSE

Examples

1
2
3
counter <- generator(0, function (state) state + 1)
recycled <- counter %>% recycle(~ state < 4)
recycled %>% take(7)

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