consume {itertools2} | R Documentation |
Consumes the first n elements of an iterator
Description
Advances the iterator n-steps ahead without returning anything.
Usage
consume(iterator, n = 0)
Arguments
iterator |
an iterator object |
n |
The number of elements to consume. |
Details
If n
is 0, the iterator is consumed entirely. Similarly, if n
is larger than the length of the iterator, the iterator is consumed entirely.
Value
Nothing, i.e., invisible(NULL)
Examples
it <- iterators::iter(1:10)
# Skips the first 5 elements
consume(it, n=5)
# Returns 6
iterators::nextElem(it)
it2 <- iterators::iter(letters)
# Skips the first 4 elements
consume(it2, 4)
# Returns 'e'
iterators::nextElem(it2)
[Package itertools2 version 0.1.1 Index]