Learn R Programming

itertools2 (version 0.1.1)

take: Return the first n elements of an iterable object as a list

Description

Returns the first n elements of an iterable object as a list. If n is larger than the number of elements in object, the entire iterator is consumed.

Usage

take(object, n = 1)

Arguments

object
an iterable object
n
the number of elements to return in the list

Value

a list of the first n items of the iterable object

Examples

Run this code
take(iterators::iter(1:10), 3) # 1 2 3

take(iterators::iter(1:5), 10) # 1 2 3 4 5

Run the code above in your browser using DataLab