Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collect + Iterators.Stateful + Base.Generator lose last element #42107

Closed
jacg opened this issue Sep 3, 2021 · 1 comment
Closed

collect + Iterators.Stateful + Base.Generator lose last element #42107

jacg opened this issue Sep 3, 2021 · 1 comment

Comments

@jacg
Copy link

jacg commented Sep 3, 2021

julia> collect(Iterators.Stateful(2x for x in 1:3))
2-element Vector{Int64}:
 2
 4

The input has 3 elements, I would therefore expect the output also to have 3 elements, but there are only 2.

On the other hand, the problem disappears if

  • we remove the generator

    collect(Iterators.Stateful(1:3))
    3-element Vector{Int64}:
     1
     2
     3
    
  • we use iterate directly

    julia> s = Iterators.Stateful(2x for x in 1:3);
    
    julia> iterate(s)
    (2, nothing)
    
    julia> iterate(s, ans[2])
    (4, nothing)
    
    julia> iterate(s, ans[2])
    (6, nothing)
    
    julia> iterate(s, ans[2])
    
    julia> 
    

versioninfo

julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, ivybridge)

julia> 

The problem also appears in julia 1.3.1, but it seems to be behaving as expected in 1.0.

Edit:

My 1.3.1 trial was in an online REPL (https://replit.com/languages/julia) which claims to be 1.3.1 but versioninfo() shows 1.4.1

julia version 1.3.1
 versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, haswell)

 collect(Iterators.Stateful(2x for x in 1:3))
2-element Array{Int64,1}:
 2
 4
@simeonschaub
Copy link
Member

Duplicate of #35530, should be fixed now by #41919.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants