Skip to contents

Returns the nth item of an iteror after advancing the iteror n steps ahead. If the iteror is entirely consumed, the argument or is returned instead. That is, if either n > length(iteror) or n is 0, then the iteror is consumed.

Usage

nth(obj, n, or, ...)

Arguments

obj

an iterable.

n

The index of the desired element to return.

or

If the iteror finishes before retuning n elements, this argument will be forced and returned.

...

passed along to iteror constructor.

Value

The nth element of the iteror or the result of forcing or.

See also

take consume collect

Examples

it <- iteror(1:10)
# Returns 5
nth(it, 5, NA)
#> [1] 5

it2 <- iteror(letters)
# Returns 'e'
nth(it2, 5, NA)
#> [1] "e"

it3 <- iteror(letters)
# Returns default value of NA
nth(it3, 42, NA)
#> [1] NA

it4 <- iteror(letters)
# Returns default value of "foo"
nth(it4, 42, or="foo")
#> [1] "foo"