Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


iterors (version 1.0)

i_break: Create an iterator that can be told to stop.

Description

Create an iterator that iterates over another iterator until a specified function returns FALSE. This can be useful for breaking out of a foreach loop, for example.

Usage

i_break(iterable, finished, ...)

Value

an iteror which will stop when finished() is TRUE

Arguments

iterable

Iterable to iterate over.

finished

Function that returns a logical value. The iterator stops when this function returns FALSE.

...

Further arguments forwarded to iteror.

Details

Originally from the itertools package.

Examples

Run this code

# See how high we can count in a tenth of a second
mkfinished <- function(time) {
  starttime <- proc.time()[3]
  function() proc.time()[3] > starttime + time
}
length(as.list(i_break(icount(), mkfinished(0.1))))

Run the code above in your browser using DataLab