| hasNext | R Documentation | 
wrapped <- ihasnext(obj) wraps an iteror object with the
ihasNext class. Then hasNext(wrapped) will indicate if the
iterator has another element.
hasNext(obj, ...)
ihasNext(obj, ...)
| obj | an iterable | 
| ... | extra arguments may be passed along to iteror. | 
A class ihasNext was introduced in the itertools
package to try to reduce the boilerplate around extracting the
next value using iterators::nextElem.  ihasNext is included
in iterors for backward compatibility with iterator code; however,
it is less needed when using the nextOr iteration method, as you can
directly give an action to take at end of iteration.
Logical value indicating whether the iterator has a next element.
# The bad old style of consuming an iterator in a loop with `nextElem`:
  it <- ihasNext(iteror(c('a', 'b', 'c')))
  tryCatch(repeat {
    print(iterators::nextElem(it))
  }, error=function(err) {
    if (conditionMessage(err) != "StopIteration")
      stop(err)
  })
# with ihasNext, this became:
  it <- ihasNext(iteror(c('a', 'b', 'c')))
  while (hasNext(it))
    print(iterators::nextElem(it))
# But using `nextOr` all you need is:
  iteror(c('a', 'b', 'c'))
  repeat print(nextOr(it, break))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.