i_tee {iterors}R Documentation

Create multiple iterators from one source

Description

i_tee(obj, n) consumes and buffers the output of a single iterator obj so that it can be read by n independent sub-iterators.

Usage

i_tee(obj, n, max = 2^16 - 1, ...)

Arguments

obj

an iterable object

n

the number of iterators to return

max

The maximum number of values to buffer.

...

passed along to iteror(obj, ...)

Details

It works by saving the output of source obj in a queue, while each sub-iterator has a "read pointer" indexing into the queue. Items are dropped from the queue after all sub-iterators have seen them.

This means that if one sub-iterator falls far behind the others, or equivalently if one sub-iterator reads far ahead its cohort the others, the intervening values will be kept in memory. The max argument gives a limit on how many items will be held. If this limit is exceeded due to one sub-iterator reading far ahead of the others, an error will be thrown when that sub-iterator attempts to read a new value.

Value

a list of n iterators.

Author(s)

Peter Meilstrup


[Package iterors version 1.0 Index]