https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112020-11-15T22:07:04ZRuby Issue Tracking SystemRuby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=885032020-11-15T22:07:04Zchrisseaton (Chris Seaton)chris@chrisseaton.com
<ul></ul><p><a href="https://github.com/ruby/ruby/pull/3768" class="external">https://github.com/ruby/ruby/pull/3768</a></p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=885042020-11-15T22:11:15Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>What about a way to bulk add items, e.g. <code>q.concat</code> or whatever is the same for Array, and maybe it would be best to have the first argument as an array, e.g. <code>Queue.new(worklist)</code>? I think it's more expensive to expand it in CRuby when you write <code>*worklist</code>.</p>
<p>Internally, this might still be adding one item at a time, in order to invoke the right "wakeup" machinery.</p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=885052020-11-15T22:13:18Zchrisseaton (Chris Seaton)chris@chrisseaton.com
<ul></ul><p>I'm not worried about <code>Queue.new(worklist)</code> or <code>Queue.new(*worklist)</code>, so that's fine if more people feel that way. I think the key thing is conciseness in text source code, and also avoiding needing to synchronise while adding each individual item.</p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=885062020-11-15T22:50:13Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>That all makes sense to me.</p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=885172020-11-16T09:11:26Zbyroot (Jean Boussier)byroot@ruby-lang.org
<ul></ul><p>I agree that the constructor should take an enumerable rather than variadic arguments, as it would be consistent with <code>Set.new([1, 2, 3])</code>, and <code>Array.new([1, 2, 3])</code></p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=885182020-11-16T12:12:12Zufuk (Ufuk Kayserilioglu)
<ul></ul><p>Agreed with <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/7941">@byroot (Jean Boussier)</a> (actually I was going to note the same, he beat me to it).</p>
<p>I would also like to note that different from <code>Set</code>, for example, the order of items in the supplied parameter matters in the <code>Queue</code> case. Even though the expected outcome is for the items to be <code>push</code>ed to the <code>Queue</code> in given order, it might still be a good idea to explicitly call that out in the method documentation.</p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=890392020-12-09T11:04:08Zchrisseaton (Chris Seaton)chris@chrisseaton.com
<ul></ul><p>I updated to take a single array rather than a variable number of arguments.</p>
<p>I had two choices for how to do this - <code>Set</code> takes an <code>Enumerable</code>, using <code>each</code> to access items, and <code>Array</code> takes another <code>Array</code>, using <code>#to_ary</code> if needed.</p>
<p>I went with the same as what <code>Array</code> does, because both <code>Array</code> and <code>Queue</code> are core libraries, where <code>Set</code> is a standard library.</p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=899062021-01-13T06:05:41Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I accept the idea. Take <code>Enumerable</code> as initial values.</p>
<p>Matz.</p> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=901452021-01-29T08:50:57Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul> Ruby master - Feature #17327: The Queue constructor should take an initial set of itemshttps://bugs.ruby-lang.org/issues/17327?journal_id=903552021-02-12T04:36:08Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Thread::Queue.new should accept an Enumerable [Feature #17327] Enumerable implements #to_a but n..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/1f0e0dfb228fd14b3f6687539ba274ba6a2d1643">git|1f0e0dfb228fd14b3f6687539ba274ba6a2d1643</a>.</p>
<hr>
<p>Thread::Queue.new should accept an Enumerable [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: The Queue constructor should take an initial set of items (Closed)" href="https://bugs.ruby-lang.org/issues/17327">#17327</a>]</p>
<p>Enumerable implements #to_a but not #to_array.</p>