See the following MWE:
julia> a = Iterators.Stateful("123456789");
julia> b = Iterators.drop(a, 3)
Base.Iterators.Drop{Base.Iterators.Stateful{String,Union{Nothing, Tuple{Char,Int64}}}}(Base.Iterators.Stateful{String,Union{Nothing, Tuple{Char,Int64}}}("123456789", ('1', 2), 0), 3)
julia> iterate(b)
('4', nothing)
julia> iterate(b)
('8', nothing)
julia> iterate(b)
# nothing
Variable b
drops the first 3 elements of a
every time iterating it.
But what I want is actually drop the “123” and iterate a
one by one.
A working way could be
julia> a = Iterators.Stateful("123456789");
julia> b = Iterators.Stateful(collect(Iterators.drop(a, 3)))
Base.Iterators.Stateful{Array{Char,1},Union{Nothing, Tuple{Char,Int64}}}(['4', '5', '6', '7', '8', '9'], ('4', 2), 0)
julia> iterate(b)
('4', nothing)
julia> iterate(b)
('5', nothing)
julia> iterate(b)
('6', nothing)
...
But if a
is large of infinitive, collect
ing is not possible.
Of course, I could write, in this example,
julia> a = Iterators.Stateful(Iterators.drop("123456789", 3));
julia> iterate(a)
('4', nothing)
julia> iterate(a)
('5', nothing)
julia> iterate(a)
('6', nothing)
from the beginning, but sometimes this is not possible. I am given a
as a Stateful
already.