Skip to content

Bug: Iterators.cycle does not work for stateful iterators #43235

@jakobnissen

Description

@jakobnissen

MWE:

julia> it = Iterators.cycle(Iterators.Stateful(1:3));

julia> z = zip(it, 1:10);

julia> length(z)
10

julia> collect(z)
10-element Vector{Tuple{Int64, Int64}}:
 (1, 1)
 (2, 2)
 (3, 3)
 (0, 0)
 (0, 0)
 (0, 0)
 (0, 0)
 (0, 0)
 (0, 0)
 (0, 0)

The 7 last elements of the vector are un-initialized and therefore set to arbitrary values (which could include #undef elements!)

This happens because Iterators.cycle assumes its underlying iterator is stateless and can be resumed from the beginning by calling iterate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavioriterationInvolves iteration or the iteration protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions