Getindex generator

I can’t find it, although I’m sure it’s been answered before: how do I (efficiently) access the 'n’th element of a generator?

a = (i for i in 1:10^6)
first(Iterators.drop(a, n-1))

What do you mean by efficiently? I think it is not possible in O(1), the best would be O(n) as the Kristoffer answer.

1 Like

I only meant not like this:

getindex(collect(a), 3)