itee: Returns a list of n independent iterators from a single...

Description Usage Arguments Details Value Examples

Description

Constructs a list of n iterators, each of which iterates through an iterable object.

Usage

1
itee(object, n = 2)

Arguments

object

an iterable object

n

the number of iterables to return

Details

If the object is an iterator (i.e., inherits from class iter), n deep copies of object are returned. Otherwise, object is passed to iter n times.

Value

a list of n iterators

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Creates a list of three iterators.
# Each iterator iterates through 1:5 independently.
iter_list <- itee(1:5, n=3)

# Consumes the first iterator
unlist(as.list(iter_list[[1]])) == 1:5

# We can iterate through the remaining two iterators in any order.
iterators::nextElem(iter_list[[2]]) # 1
iterators::nextElem(iter_list[[2]]) # 2

iterators::nextElem(iter_list[[3]]) # 1
iterators::nextElem(iter_list[[3]]) # 2

iterators::nextElem(iter_list[[2]]) # 3
iterators::nextElem(iter_list[[2]]) # 4
iterators::nextElem(iter_list[[2]]) # 5

iterators::nextElem(iter_list[[3]]) # 3
iterators::nextElem(iter_list[[3]]) # 4
iterators::nextElem(iter_list[[3]]) # 5

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