迭代器的迭代器?

时间:2018-07-16 05:34:03

标签: r iterator

有没有一种方法可以将迭代器存储为包装迭代器的元素?例如:

iterOfIter <- function() {
  L <- list()
  for ( n in seq(1,5) ) {
    L <- append( L, iter( c(1,2,3) ) )
  }
  iter(L)
}

不会产生错误,但是在运行时会产生:

> ii <- iterOfIter()
> i <- nextElem(ii)
> nextElem(i)
Error in UseMethod("nextElem") : 
  no applicable method for 'nextElem' applied to an object of class    "environment"
> class(i)
[1] "environment"

理想情况下,我想致电:

> ii <- iterOfIter()
> i <- nextElem(ii)
> nextElem(i)
[1] 1
> nextElem(i)
[1] 2
> nextElem(i)
[1] 3
> i <- nextElem(ii)
> nextElem(i)
[1] 1
... and so on.

0 个答案:

没有答案