# an iterator that counts from start to stop
irange <- function(from=1, to=Inf) {
current <- from
iteror(function(or) {
if (current > to) {
return(or)
} else {
tmp <- current
current <<- current + 1
tmp
}
})
}
it <- irange(5, 10)
as.vector(it, "numeric")
# an endless random number generator
irand <- function(min, max) {
iteror(function() runif(1, min=min, max=max), count=Inf)
}
take(irand(5, 10), 10)
Run the code above in your browser using DataLab