# NOT RUN {
# Iterator on primitive list
it <- Iterator$new(list("A", 1, 2))
while(it$has_next()) {
print(it$get_next())
}
it$has_next() # FALSE
print(it) # <Iterator> at position 3
it$begin()
print(it) # <Iterator> at position 0
# Iterator from Container object
d <- deque(1:3)
it <- iter(d)
sum <- 0
while(it$has_next()) {
sum <- sum + it$get_next()
}
print(sum)
# S3 method interface
it <- iter(list("A", 1, 2))
while(ithas_next(it)) {
print(itget_next(it))
}
ithas_next(it) # FALSE
print(it) # <Iterator> at position 3
itbegin(it)
print(it) # <Iterator> at position 0
# }
Run the code above in your browser using DataLab