Iterator | R Documentation |
An Iterator
is an object that allows to iterate over
sequences. It implements next_iter
and get_value
to iterate and retrieve the
value of the sequence it is associated with.
For the standard S3 interface, see iter()
.
new()
Iterator
constructor
Iterator$new(x, .subset = .subset2)
x
object to iterate over
.subset
accessor function
invisibly returns the Iterator
object
begin()
set iterator to the first element of the underlying sequence unless length of sequence is zero, in which case it will point to nothing.
Iterator$begin()
invisibly returns the Iterator
object
get_value()
get value where the iterator points to
Iterator$get_value()
returns the value the Iterator
is pointing at.
get_next()
get next value
Iterator$get_next()
increments the iterator and returns the value the Iterator
is pointing to.
has_next()
check if iterator
has more elements
Iterator$has_next()
TRUE
if iterator
has next element else FALSE
has_value()
check if iterator
points at value
Iterator$has_value()
TRUE
if iterator
points at value otherwise FALSE
length()
iterator length
Iterator$length()
number of elements to iterate
pos()
get iterator position
Iterator$pos()
integer
if iterator
has next element else FALSE
next_iter()
increment iterator
Iterator$next_iter()
invisibly returns the Iterator
object
print()
print method
Iterator$print()
reset_iter()
reset iterator to '0'
Iterator$reset_iter()
invisibly returns the Iterator
object
clone()
The objects of this class are cloneable with this method.
Iterator$clone(deep = FALSE)
deep
Whether to make a deep clone.
Roman Pahl
# Numeric Vector v = 1:3 it = Iterator$new(v) it try(it$get_value()) # iterator does not point at a value it$has_value() it$has_next() it$next_iter() it$get_value() it$get_next() it$get_next() it it$has_next() it$begin() it$get_value() it$reset_iter() # Works by reference for Container co = Container$new(1, 2, 3) it = co$iter() it$get_next() co$discard(2) it it$get_value() co$discard(1) it it$get_value() it$begin()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.