File: iforever.R

package info (click to toggle)
r-cran-iterators 1.0.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 532 kB
  • sloc: sh: 29; makefile: 1
file content (16 lines) | stat: -rw-r--r-- 351 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
library(iterators)

# return an iterator that returns the specified value forever
iforever <- function(x) {
  nextEl <- function() x
  obj <- list(nextElem=nextEl)
  class(obj) <- c('iforever', 'abstractiter', 'iter')
  obj
}

# create an iterator that returns 42 forever
it <- iforever(42)

# call it three times
for (i in 1:3)
  print(nextElem(it))