https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112018-09-14T19:43:41ZRuby Issue Tracking SystemRuby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=740452018-09-14T19:43:41Zgreggzst (Grzegorz Jakubiak)
<ul></ul><p>I'm in favor of this proposal. It simplifies working with large and small collections so one doesn't have to remember that can't use <code>#compact</code> when enumerator is returned and have to fall back to <code>#reject(:nil?)</code>.</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=740492018-09-15T02:37:41Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>Proposal seems acceptable to me.</p>
<p>Just to be clear: I imagine that <code>Lazy#compact</code> would still be lazy. Also <code>compact</code> is roughly <code>select(&:itself)</code>, not <code>reject(&:nil?)</code> which would wrongly keep <code>false</code>.</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=740512018-09-15T07:45:59ZEregon (Benoit Daloze)
<ul></ul><p>marcandre (Marc-Andre Lafortune) wrote:</p>
<blockquote>
<p>Also <code>compact</code> is roughly <code>select(&:itself)</code>, not <code>reject(&:nil?)</code> which would wrongly keep <code>false</code>.</p>
</blockquote>
<p>No, #compact only removes <code>nil</code>: <code>["a" ,false ,nil].compact</code> => <code>["a", false]</code>.</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=740532018-09-15T11:06:16Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I think if the meaning is consistent (e. g. .compact meaning to eliminate<br>
nil values from a given collection) then this seems ok. Perhaps this could<br>
be added for the next developer meeting.</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=740552018-09-15T14:38:49Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>No, #compact only removes <code>nil</code>: <code>["a" ,false ,nil].compact</code> => <code>["a", false]</code>.</p>
</blockquote>
<p>Lol, ouch, not sure how I could be so confused when I wrote that, sorry!</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=741782018-09-24T23:07:47Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>Backport</strong> deleted (<del><i>2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN</i></del>)</li></ul> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=780882019-05-20T07:23:05Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>Just leaving a comment that I wanted this method in my pet project just now. So +1.</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=813342019-09-02T05:28:45Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I don't see enough demand for <code>compact</code> where we have <code>reject(&:nil?)</code>. Any additional use-case?</p>
<p>Matz.</p> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=820692019-10-16T08:55:25Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul> Ruby master - Feature #15123: Enumerable#compact proposalhttps://bugs.ruby-lang.org/issues/15123?journal_id=823822019-10-30T19:30:46Zbaweaver (Brandon Weaver)keystonelemur@gmail.com
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/13">@matz (Yukihiro Matsumoto)</a>: Its presence in Array and Hash make it more of a common interface that I could see being defined for Enumerable in general, though the immediate usecases are around Lazy. As mentioned above, sometimes one wants to use Enumerators directly or returns one from an Enumerable method which can cause some conflicts of available methods.</p>
<p>I believe it could be considered surprising that <code>compact</code> does not necessarily work with all collection-like types.</p>