Project

General

Profile

Actions

Bug #6428

closed

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

Added by nagachika (Tomoyuki Chikanaga) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2012-05-12 trunk 35629) [x86_64-darwin10.8.0]
Backport:
[ruby-dev:45634]

Description

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

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

p lazy_take.force
p lazy_take.force

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

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


Files

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

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #7691: 3 bugs with Lazy enumerators with stateClosed01/14/2013Actions

Updated by matz (Yukihiro Matsumoto) over 12 years ago

  • Assignee set to nagachika (Tomoyuki Chikanaga)

コミットしてください。

Actions #2

Updated by nagachika (Tomoyuki Chikanaga) over 12 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 (lazy_take_func, lazy_take): multiple calls of
    force/to_a method to Enumerator::Lazy#take should return same
    results. [ruby-dev:45634] [Bug #6428]

  • test/ruby/test_lazy_enumerator.rb (test_take_recycle): add test for
    above.

Actions

Also available in: Atom PDF

Like0
Like0Like0