https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-03-14T22:31:37ZRuby Issue Tracking SystemRuby master - Bug #6142: Enumerable::Lazy#zip doesn't rewind internal enumeratorshttps://bugs.ruby-lang.org/issues/6142?journal_id=245782012-03-14T22:31:37Ztrans (Thomas Sawyer)
<ul></ul><p>A touch OT, but is Brian Candler being involved in the development of this? I don't know of anyone who has discussed and worked on this topic more over the years than Brian and I think it would be most prudent to seek his consul on these matters.</p>
<p>(Not to speak for Brain, of course, but just saying.)</p> Ruby master - Bug #6142: Enumerable::Lazy#zip doesn't rewind internal enumeratorshttps://bugs.ruby-lang.org/issues/6142?journal_id=246232012-03-16T12:03:36Zshugo (Shugo Maeda)
<ul><li><strong>File</strong> <a href="/attachments/2506">lazy_zip_to_a.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2506/lazy_zip_to_a.diff">lazy_zip_to_a.diff</a> added</li></ul><p>Innokenty Mikhailov wrote:</p>
<blockquote>
<p>a = (1..3).lazy.zip('a'..'z')<br>
a.to_a #=> [[1, "a"], [2, "b"], [3, "c"]]<br>
a.to_a #=> [[1, "d"], [2, "e"], [3, "f"]]</p>
<p>I believe that is not the desired behavior here and a.to_a should always return the same value.</p>
</blockquote>
<p>I agree that the current behavior is confusing, and the attached patch fixes it in the above case, but the patch cannot fix it in the following case:</p>
<p>a = (1..3).lazy.zip('a'..'z').map {|i| i.join(":")}<br>
p a.to_a #=> ["1:a", "2:b", "3:c"]<br>
p a.to_a #=> ["1:d", "2:e", "3:f"]</p>
<p>It may be difficult to fix it without performance decrease.<br>
We have three options:</p>
<p>(1) Keep the current behavior.<br>
(2) Rewind enumerators only when to_a is directly invoked on the lazy enumerator returned by lazy.zip.<br>
(3) Rewind enumerators even if to_a is invoked on a chained enumerator. This may cause performance decrease.</p> Ruby master - Bug #6142: Enumerable::Lazy#zip doesn't rewind internal enumeratorshttps://bugs.ruby-lang.org/issues/6142?journal_id=246242012-03-16T12:07:03Zshugo (Shugo Maeda)
<ul></ul><p>Thomas Sawyer wrote:</p>
<blockquote>
<p>A touch OT, but is Brian Candler being involved in the development of this? I don't know of anyone who has discussed and worked on this topic more over the years than Brian and I think it would be most prudent to seek his consul on these matters.</p>
</blockquote>
<p>Any comments from Brian and others are welcome.<br>
If there is something wrong with the current behavior, please file a ticket or send a mail to ruby-core.</p> Ruby master - Bug #6142: Enumerable::Lazy#zip doesn't rewind internal enumeratorshttps://bugs.ruby-lang.org/issues/6142?journal_id=250682012-03-23T18:43:38Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li><li><strong>Assignee</strong> set to <i>shugo (Shugo Maeda)</i></li></ul> Ruby master - Bug #6142: Enumerable::Lazy#zip doesn't rewind internal enumeratorshttps://bugs.ruby-lang.org/issues/6142?journal_id=354822013-01-19T10:39:40Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul><p>This issue should be discussed in <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: 3 bugs with Lazy enumerators with state (Closed)" href="https://bugs.ruby-lang.org/issues/7691">#7691</a> and <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Lazy enumerators with state can't be rewound (Closed)" href="https://bugs.ruby-lang.org/issues/7696">#7696</a>.</p>