diff --git a/base/iterators.jl b/base/iterators.jl index b513d78c89d344..449e8dbb0663d3 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -906,7 +906,13 @@ length(f::Flatten{Tuple{}}) = 0 end x = (state === () ? iterate(f.it) : iterate(f.it, state[1])) x === nothing && return nothing - iterate(f, (x[2], x[1])) + y = iterate(x[1]) + while y === nothing + x = iterate(f.it, x[2]) + x === nothing && return nothing + y = iterate(x[1]) + end + return y[1], (x[2], x[1], y[2]) end reverse(f::Flatten) = Flatten(reverse(itr) for itr in reverse(f.it))