Iterate through iterator starting and ending at a specified value

I have an iterator. How do I iterator through a selection of it?

E.g.

it = Iterators.product([[1,2,3],[1,2]]...)
foreach(x->println(x),it)

iterates through all 6 values. But say I want to iterate starting with the 2nd value and end with the 5th value. How do I do that?

It’s a bit clumsy, but something like this:

julia> dropends(it, start, stop) = Iterators.drop(Iterators.take(it, stop), start - 1)
dropends (generic function with 1 method)

julia> foreach(println, dropends(it, 2, 5))
(2, 1)
(3, 1)
(1, 2)
(2, 2)
2 Likes

Thanks :slight_smile:

(Bonus thanks for showing that foreach(x->println(x),it) and foreach(println,it) are equivalent!)