Learn R Programming

itertools (version 0.1-3)

is.iterator: Utilities for writing iterators

Description

is.iterator indicates if an object is an iterator. end_iteration throws an exception to signal that there are no more values available in an iterator. iteration_has_ended tests an exception to see if it indicates that iteration has ended. new_iterator returns an iterator object.

Usage

is.iterator(x) end_iteration() iteration_has_ended(e) new_iterator(nextElem, ...)

Arguments

x
any object.
e
a condition object.
nextElem
a function object that takes no arguments.
...
not currently used.

Examples

Run this code
# Manually iterate using the iteration_has_ended function to help
it <- iter(1:3)
tryCatch({
  stopifnot(is.iterator(it))
  repeat {
    print(nextElem(it))
  }
},
error=function(e) {
  if (!iteration_has_ended(e)) {
    stop(e)
  }
})

Run the code above in your browser using DataLab