Am I missing an idiomatic way to accomplish what I’d like without reifying the collection? If not, it might make a nice addition to IterTools. I’m using v0.7.0.
What does the return value indicate? It’s not an index, since a general iterator cannot be indexed. So to use it, you would anyway need to collect your iterator in one way or another. Or your iterator should be indexable, in which case it could probably be a subtype of AbstractVector.
Anyway, given the function f that needs to evaluate to true, it’s as simple as this:
for (i,v) in enumerate(iterator)
f(v) && return i
end
Good point Jutho. My use case was to check wheher some element of the collection satisfied a particular property so the better approach is to use any(predicate,collection) which does accept iterators.
This has been raised a few times before, and a solution which has been proposed is to provide a (say) withlinearindices wrapper which would do as if the input iterator used linear indices starting from 1.