https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17097754782013-01-25T12:09:32ZRuby Issue Tracking SystemRuby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=355952013-01-25T12:09:32Zko1 (Koichi Sasada)
<ul><li><strong>Target version</strong> set to <i>2.0.0</i></li></ul><p>Who's ball?</p> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=356252013-01-25T15:20:02Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>marcandre (Marc-Andre Lafortune)</i></li></ul><p>I can do it, unless there are objections.</p> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=356292013-01-25T18:24:26Zshugo (Shugo Maeda)
<ul></ul><p>marcandre (Marc-Andre Lafortune) wrote:</p>
<blockquote>
<p>I can do it, unless there are objections.</p>
</blockquote>
<p>Your proposal sounds reasonable.<br>
I guess these methods were forgotten to change when lazy was implemented.</p> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=356302013-01-25T18:29:08Zyhara (Yutaka HARA)
<ul></ul><p>shugo (Shugo Maeda) wrote:</p>
<blockquote>
<p>I guess these methods were forgotten to change when lazy was implemented.</p>
</blockquote>
<p>That's right :-( I thought these methods does not need to be overriden<br>
because they return Enumerator, but they should return Enumerator::Lazy for such cases.</p> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=358142013-02-04T09:12:44Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>I believe I have found the key to resolve this issue, Lazy.new issue [<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Shouldn't Enumerator::Lazy.new be private? (Closed)" href="https://redmine.ruby-lang.org/issues/7248">#7248</a>] and others.</p>
<p>We simply need to specialize <code>to_enum/enum_for</code> for lazy enumerators.</p>
<p>In the same way, RETURN_SIZED_ENUMERATOR should return a lazy enumerator, when called for a lazy enumerator.</p>
<p>With this in mind:</p>
<ul>
<li>Lazy.each_with_object, etc..., will correctly return lazy enumerators [<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Lazy enumerators should want to stay lazy. (Closed)" href="https://redmine.ruby-lang.org/issues/7715">#7715</a>] without being overriden.</li>
<li>Lazy#cycle can be removed. It no longer needs to be overriden.</li>
<li>Lazy.new really has no need to accept (method, *args) and can be modified as proposed in [<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Shouldn't Enumerator::Lazy.new be private? (Closed)" href="https://redmine.ruby-lang.org/issues/7248">#7248</a>]</li>
<li>Any user method of Enumerable that returns an Enumerator using <code>to_enum</code> will conserve laziness.</li>
</ul>
<p>None of this could create a regression, since Lazy & RETURN_SIZED_ENUMERATOR are both new to 2.0.0</p>
<p>I'm working on a patch...</p> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=358262013-02-04T16:52:51Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>Patch almost done, which also fixes <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Shouldn't Enumerator::Lazy.new be private? (Closed)" href="https://redmine.ruby-lang.org/issues/7248">#7248</a></p>
<p><a href="https://github.com/marcandre/ruby/compare/marcandre:master...marcandre:lazy" class="external">https://github.com/marcandre/ruby/compare/marcandre:master...marcandre:lazy</a></p>
<p>Still missing:</p>
<ul>
<li>tweak inspect</li>
<li>fix .lazy.size</li>
<li>couple more tests</li>
</ul> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=358362013-02-05T07:32:03Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>Patch updated, rdoc improved too.</p>
<p>Makes for a clean API for Lazy#new also, and there's even less code (~20 loc).</p>
<p>I'll review the patch one last time before committing it (in about 5 hours).</p> Ruby master - Bug #7715: Lazy enumerators should want to stay lazy.https://redmine.ruby-lang.org/issues/7715?journal_id=358452013-02-05T12:50:01Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r39058.<br>
Marc-Andre, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>enumerator.c: Use to_enum for Enumerable methods returning Enumerators.<br>
This makes Lazy#cycle no longer needed, so it was removed.<br>
Make Enumerator#chunk and slice_before return lazy Enumerators.<br>
[Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Lazy enumerators should want to stay lazy. (Closed)" href="https://redmine.ruby-lang.org/issues/7715">#7715</a>]</p>
</li>
<li>
<p>internal.h: Remove ref to rb_enum_cycle_size; no longer needed</p>
</li>
<li>
<p>enum.c: Make enum_cycle_size static.</p>
</li>
<li>
<p>test/ruby/test_lazy_enumerator.rb: Test for above</p>
</li>
</ul>