Better handling of iterators by izip
Closed this issue · 1 comments
ramhiser commented
When izip
is applied to objects of class iterator
, the results are a bit confusing and are quite different from Python's itertools
.
R version:
> it <- izip(islice('ABCDEFG', 2, 4), islice('ABCDEFG', 1, 3))
> nextElem(it)
Error: StopIteration
Compare with the Python version:
>>> from itertools import izip, islice
>>> it = izip(islice('ABCDEFG', 2, 4), islice('ABCDEFG', 0, 2))
>>> it.next()
('C', 'A')
>>> it.next()
('D', 'B')
>>> it.next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
ramhiser commented
Similar to #30, the above R example is actually working as expected because character vectors in R are not iterables.
Consider the following R example.
> it <- izip(islice(1:10, 2, 4), islice(1:10, 1, 3))
> nextElem(it)
[[1]]
[1] 2
[[2]]
[1] 1
> nextElem(it)
[[1]]
[1] 3
[[2]]
[1] 2
> nextElem(it)
[[1]]
[1] 4
[[2]]
[1] 3
!> nextElem(it)
Error: StopIteration