ramhiser/itertools2

itee does not work properly when an iterator is passed

Closed this issue · 1 comments

When an iterator is passed to itee, the function does not behave as expected.

When the object passed is simply a vector, then the behavior is fine. Example:

 > iter_list <- itee(1:4, n=2)
 > lapply(iter_list, iterators::nextElem)
 [[1]]
 [1] 1

 [[2]]
 [1] 1

 > lapply(iter_list, iterators::nextElem)
 [[1]]
 [1] 2

 [[2]]
 [1] 2

 > lapply(iter_list, iterators::nextElem)
 [[1]]
 [1] 3

 [[2]]
 [1] 3

 > lapply(iter_list, iterators::nextElem)
 [[1]]
 [1] 4

 [[2]]
 [1] 4

!> lapply(iter_list, iterators::nextElem)
 Error: StopIteration

Now, consider the same case where the vector has first been passed to iterators::iter.

 > iter_list <- itee(iterators::iter(1:4), n=2)
 > lapply(iter_list, iterators::nextElem)
 [[1]]
 [1] 1

 [[2]]
 [1] 2

 > lapply(iter_list, iterators::nextElem)
 [[1]]
 [1] 3

 [[2]]
 [1] 4

!> lapply(iter_list, iterators::nextElem)
 Error: StopIteration

The individual elements are not independent of each other as they should be. This has to do with how itee behaves currently. The passed object is replicated via base::replicate.

Currently, a test for ipairwise() fails because of the issue above.