Skip to content

Stateful Iterator omitting last element when used in list comprehension, crashes on 1-element long vectors. #35530

@racinmat

Description

@racinmat

Strage behaviour of Stateful iterator:
Although

julia> for a in Iterators.Stateful([1,2,3])
             print(a)
         end
123

works as it should,
With list comprehension it fails to iterate over last element

julia> [a for a in Iterators.Stateful([1,2,3])]
2-element Array{Int64,1}:
 1
 2
julia> [a for a in Iterators.Stateful([1])]
ERROR: BoundsError: attempt to access 0-element Array{Int64,1} at index [1]

tried on Julia 1.3.1, Julia 1.4.0 and Julia 1.4.1.
More details in https://discourse.julialang.org/t/strange-behavior-with-list-comprehensions-using-iterators-stateful/29715

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions