consume: Consumes the first n elements of an iterator

Description Usage Arguments Details Value Examples

Description

Advances the iterator n-steps ahead without returning anything.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)

itertools2 documentation built on May 2, 2019, 3:37 p.m.