Bug #6428

lazy版take/dropに2度forceを呼んだ時の挙動

Added by Tomoyuki Chikanaga almost 2 years ago. Updated almost 2 years ago.

[ruby-dev:45634]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga
Category:core
Target version:2.0.0
ruby -v:ruby 2.0.0dev (2012-05-12 trunk 35629) [x86_64-darwin10.8.0] Backport:

Description

Enumerator::Lazy#take が返す Enumerator::Lazy に繰り返し force/to_a メソッドを呼ぶと、
2度目以降は全ての要素を返しています。

$ cat lazytakerecycle.rb
lazy_take = (1..5).lazy.take(3)

p lazytake.force
p lazy
take.force

$ ruby lazytakerecycle.rb
[1, 2, 3]
[1, 2, 3, 4, 5]

同じ Enumerator::Lazy に force を複数回呼ぶのがよい使いかたではないのかもしれませんが、
なんとなく何度呼んでも先頭の要素を返してくれるのが嬉しいのではないかと思います。
2度目以降も同じ個数になるようにするパッチを添付します。
ただし実用的なユースケースがあるわけではありません。

lazy_take_recycle.patch Magnifier (1.2 KB) Tomoyuki Chikanaga, 05/13/2012 01:52 AM


Related issues

Related to ruby-trunk - Bug #7691: 3 bugs with Lazy enumerators with state Closed 01/14/2013

Associated revisions

Revision 35638
Added by Tomoyuki Chikanaga almost 2 years ago

  • enumerator.c (lazytakefunc, lazytake): multiple calls of
    force/to
    a method to Enumerator::Lazy#take should return same
    results. [Bug #6428]

  • test/ruby/testlazyenumerator.rb (testtakerecycle): add test for
    above.

History

#1 Updated by Yukihiro Matsumoto almost 2 years ago

  • Assignee set to Tomoyuki Chikanaga

コミットしてください。

#2 Updated by Tomoyuki Chikanaga almost 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35638.
Tomoyuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • enumerator.c (lazytakefunc, lazytake): multiple calls of
    force/to
    a method to Enumerator::Lazy#take should return same
    results. [Bug #6428]

  • test/ruby/testlazyenumerator.rb (testtakerecycle): add test for
    above.

Also available in: Atom PDF