Project

General

Profile

Actions

Bug #7691

closed

3 bugs with Lazy enumerators with state

Added by marcandre (Marc-Andre Lafortune) almost 12 years ago. Updated almost 12 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
r38800
Backport:
[ruby-core:51420]

Description

I found the following 3 bugs with Lazy#drop, drop_while and zip:

drop = (1..4).lazy.drop(2)
drop.to_a # => [3, 4]
drop.to_a # => [1, 2, 3, 4], should be same as above

drop_while = (1..4).lazy.drop_while(&:odd?)
drop_while.to_a # => [2, 3, 4]
drop_while.to_a # => [1, 2, 3, 4], should be same as above

zip = (1..2).lazy.zip([3, 4])  # or (3..4)
zip.to_a # => [[1, 3], [2, 4]]
zip.to_a # => [[1, nil], [2, nil]] should be same as above

I found them when writing a Ruby implementation of Enumerator::Lazy.

My implementation created the same bug with #take as described in https://bugs.ruby-lang.org/issues/6428.

This made me realize that the api of Lazy.new makes it near impossible to write most lazy enumerators requiring a state, as there is no general way to reset that state.

When looking at my code, I used a state for drop, drop_while and zip. A quick verification showed me that the MRI implementation also has the same bugs!gene

So the meta question is: should there not be a general way to initialize the state of the lazy enum?


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #7696: Lazy enumerators with state can't be rewoundClosedmatz (Yukihiro Matsumoto)01/15/2013Actions
Related to Ruby master - Bug #6428: lazy版take/dropに2度forceを呼んだ時の挙動Closednagachika (Tomoyuki Chikanaga)05/13/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0