# 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))
Run the code above in your browser using DataLab