icycle: Iterator that cycles indefinitely through an iterable object

Description Usage Arguments Details Value Examples

Description

Constructs an iterator that returns an iterable object in sequence over and over again.

Usage

1
icycle(object, times = NULL)

Arguments

object

object to cycle indefinitely.

times

the number of times object is returned. If NULL (default), object is returned indefinitely.

Details

Runs indefinitely unless the times argument is specified.

Value

iterator that returns object in sequence

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
it <- icycle(1:3)
iterators::nextElem(it) # 1
iterators::nextElem(it) # 2
iterators::nextElem(it) # 3
iterators::nextElem(it) # 1
iterators::nextElem(it) # 2
iterators::nextElem(it) # 3
iterators::nextElem(it) # 1

it2 <- icycle(1:3, times=2)
as.list(it2)

# Can return the results from a function.
it3 <- icycle(function() rnorm(1))
iterators::nextElem(it)
iterators::nextElem(it)
iterators::nextElem(it)
iterators::nextElem(it)

itertools2 documentation built on May 2, 2019, 3:37 p.m.