https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112011-04-27T13:06:00ZRuby Issue Tracking SystemRuby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=166702011-04-27T13:06:00Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>=begin<br>
At first I thought this would be a good idea. But then I realized that #each is, in every case I can think of, a non-mutating operation. Since I assume you meant for Queue#each to pop all elements off the queue, this would be the first example I know of a mutating #each.</p>
<p>Also, what happens when the queue is empty? Does it wait for another element, or does it end the iteration?</p>
<p>The behavior of #each over a queue seems fuzzy to me, and without a clear specification of what you want I don't see a path forward.<br>
=end</p> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=167042011-04-29T06:50:36Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul></ul><p>=begin<br>
I don't think it is appropriate to include Enumerable. Too many methods from Enumerable seem inappropriate (or behavior would be application-specific). For example, should #find block, or only return items that match in the Queue? Should #reject remove items from the Queue, or only filter?</p>
<p>I can see differing needs depending on if the Queue has a single consumer or multiple consumers.<br>
=end</p> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=197372011-07-27T03:21:07Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>Perhaps this code example can better illustrate my request:</p>
<p>class Queue<br>
def each(&block)<br>
temporary_copy = @internal_queue_lock.synchronize do<br>
@internal_item_array.dup<br>
end<br>
temporary_copy.each(&block)<br>
end<br>
end</p>
<p>Charles Nutter wrote:</p>
<blockquote>
<p>At first I thought this would be a good idea. But then I realized<br>
that #each is, in every case I can think of, a non-mutating<br>
operation.</p>
</blockquote>
<p>Yes, that was my intention: read-only iteration of the queue.</p>
<blockquote>
<p>Since I assume you meant for Queue#each to pop all elements off<br>
the queue, this would be the first example I know of a mutating<br>
#each.</p>
</blockquote>
<p>Sorry if my request was unclear, but that is not what I requested.</p>
<blockquote>
<p>Also, what happens when the queue is empty? Does it wait for<br>
another element, or does it end the iteration?</p>
</blockquote>
<p>It should be non-blocking. Simply iterate over the items that are<br>
currently in the queue.</p>
<p>If the method was blocking, it would never finish, because we would<br>
never reach the "end" of the queue.</p>
<blockquote>
<p>The behavior of #each over a queue seems fuzzy to me, and without<br>
a clear specification of what you want I don't see a path forward.</p>
</blockquote>
<p>I hope my responses above clarify this feature request.</p>
<p>Eric Hodel wrote:</p>
<blockquote>
<p>I don't think it is appropriate to include Enumerable. Too many<br>
methods from Enumerable seem inappropriate (or behavior would be<br>
application-specific). For example, should #find block, or only<br>
return items that match in the Queue?</p>
</blockquote>
<p>Since Enumerable relies on #each(), and the Queue#each method I'm<br>
requesting is non-blocking, all of the non-destructive Enumerable<br>
methods (like #find, #select, #map) should work as we normally<br>
expect them to.</p>
<blockquote>
<p>Should #reject remove items from the Queue, or only filter?</p>
</blockquote>
<p>#reject should filter (read-only). #reject! should remove items.</p>
<blockquote>
<p>I can see differing needs depending on if the Queue has a single<br>
consumer or multiple consumers.</p>
</blockquote>
<p>Hmm, shouldn't the thread-safe aspect of Queue take care of that?</p> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=197442011-07-27T08:34:47Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul></ul><p>There are no destructive methods in Enumerable.</p>
<p>Most times I use a Queue I am producing and consuming items at the same time so this would not be as useful for me since it works on a copy.</p>
<p>If I were to finish production of items or work with partial results this would be useful.</p> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=197722011-07-27T18:53:07Zregularfry (Alex Young)alex@blackkettle.org
<ul></ul><p>On 27/07/11 00:34, Eric Hodel wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: add Queue#each() method and include Enumerable (Closed)" href="https://bugs.ruby-lang.org/issues/4589">#4589</a> has been updated by Eric Hodel.</p>
<p>There are no destructive methods in Enumerable.</p>
</blockquote>
<p>Enumerable gets mixed into IO, and #each on a Socket <em>is</em> destructive<br>
(of the buffer contents). In that sense there is precedent for this sort<br>
of behaviour.</p>
<p>--<br>
Alex</p> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=251152012-03-25T15:20:23Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=319422012-10-30T08:43:45Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Feedback</i></li><li><strong>Target version</strong> set to <i>2.6</i></li></ul><p>Professional's comments are very welcome.<br>
I can't determine it should be worth or not.</p> Ruby master - Feature #4589: add Queue#each() method and include Enumerablehttps://bugs.ruby-lang.org/issues/4589?journal_id=627712017-01-31T09:10:38Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul><p>No discussion.</p>