<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="334492" data-post-id="334492">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pejrich" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pejrich/120/14576_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pejrich
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You are correct about <code>filter</code> working on predicates. I very quickly glanced this <code>map().filter().map()</code> in the <code>filter_map</code> docs, and assumed there was a <code>filter()</code> function without a predicate. But it does appear from the example that <code>filter_map</code> does merely remove <code>None</code>, and doesn’t take a predicate.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">let a = ["1", "two", "NaN", "four", "5"];

let mut iter = a.iter().filter_map(|s| s.parse().ok());

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(5));
assert_eq!(iter.next(), None);
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334492" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-334492" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334492"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="334493" data-post-id="334493">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pejrich" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pejrich/120/14576_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pejrich
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m still not sure I understand your point. Is your point that nothing new should be added to the language, period? Since <code>reduce</code> covers the Enum operations, should we have stopped there? Everything beyond that adds some mental overhead for a beginner. If your point is to just not add anything new, fair enough, point taken. But if it’s more nuanced, then surely at some point you’ll have to judge something in a relative vacuum, right?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334493" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-334493" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334493"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="334497" data-post-id="334497">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="fmn" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fmn/120/26825_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  fmn
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="pejrich" data-post="13" data-topic="64915" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pejrich/48/14576_2.png" class="avatar"> pejrich:</div>
<blockquote>
<p>I’m still not sure I understand your point. Is your point that nothing new should be added to the language, period?</p>
</blockquote>
</aside>
<p>no, not at all. as i wrote above:</p>
<p><em>IMHO it’s easier to add stuff than remove from a language, and more verbose, complex, expressive syntax is, higher entry threshold for proposal as yours should be.</em></p>
<p>my point is that, if you will grow language syntax, make it more complex for relatively small wins, you will bloat it, because you will never be able to decommission and deprecate enough other, alternative syntaxes to balance the growth.</p>
<p>i think our reference frame to judge such additions should be broader, to see where language will go after - let’s say - 30 such additions over 2-5 years.</p>
<p>discussing “proposal vs <code>reduce</code>” is just “too confined”, in my opinion.</p>
<aside class="quote no-group">
<blockquote>
<p>Since <code>reduce</code> covers the Enum operations, should we have stopped there?</p>
</blockquote>
</aside>
<p>i don’t want to send contradictory signals, but i still think such proposals are worth discussing, and of course i am not saying language is finished and the best, and there is nothing to improve. it just doesn’t mean it will be easy to push such proposals through or that even majority of them are worth it.</p>
<aside class="quote no-group">
<blockquote>
<p>Everything beyond that adds some mental overhead for a beginner.</p>
</blockquote>
</aside>
<p>i don’t believe way you are framing it is correct. overhead we are talking about is a cost for everyone, no matter how advanced or smart you are. language complexity will always impose load on you, no matter who you are.</p>
<p>also, who is average user of the language? genius developer? blue collar coder?</p>
<aside class="quote no-group">
<blockquote>
<p>If your point is to just not add anything new, fair enough, point taken. But if it’s more nuanced, then surely at some point you’ll have to judge something in a relative vacuum, right?</p>
</blockquote>
</aside>
<p>again, i am <em><strong>not</strong></em> saying nothing new should be added. please check what i wrote above.</p>
<p>personally, i am quite happy with tools Elixir gives me already, and to me cost of introducing changes you are proposing is much higher than perceived benefits.<br>
just an opinion of a random guy from the internet <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334497" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-334497" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334497"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="334517" data-post-id="334517">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gregvaughn" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/120/954_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gregvaughn
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m kinda surprised no one has mentioned for comprehensions. When I think of map/flat_map with a filter, that’s where my mind goes. Of course, to some people’s taste, this may be even more golf-y than flat_map <img src="https://forum.elixirforum.com/images/emoji/apple/person_shrugging.png?v=15" title=":person_shrugging:" class="emoji" alt=":person_shrugging:" loading="lazy" width="20" height="20"> Here’s how I’d do it in one line, a single pass through the Enumerable, and no extra List.wrap:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(29)&gt; for x &lt;- [1, 2, 3, 4], y = x + 1, Integer.is_odd(y), do: y
[3, 5]
</code></pre>
<p>edit: I thought of a better example where we use a helper function that may return nil or not which fits more closely with the original situation</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(30)&gt; odd_to_nil = fn x -&gt; if Integer.is_odd(x), do: nil, else: x end
#Function&lt;42.105768164/1 in :erl_eval.expr/6&gt;
iex(31)&gt; for x &lt;- [1, 2, 3, 4], y = odd_to_nil.(x), do: y
[2, 4]
</code></pre>
<p>The main piece to understand are filters in for comprehensions. If you have a clause that is not a generator, it’s a filter. If it evaluates to falsy, then the <code>do</code> block is <strong>not</strong> executed and the next iteration begins.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334517" data-batch-url="/posts/batch_likers">
                        9
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-334517" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334517"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="334528" data-post-id="334528">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sodapopcan" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/120/34668_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sodapopcan
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m generally happy with status quo but would use it if it were available.  Even though it makes sense and I can’t think of anything better, there’s something about the term “compact” that I never liked for this use-case, so in a weird way I’ve enjoyed being forced to “reject nils” in so many words.</p>
<p>Also, there is something off about a function that has “map” in its name that doesn’t return a list of the same size that went into it.  Though there are probably examples I’m not thinking of… like <code>map_reduce</code>, though the original length map is still in there <img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"></p>
<p>EDIT: I re-read the thread and had missed <a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a>’s message re: <code>filter_map</code> which I believe Elixir actually used to have?  In any event, there is precedence when it comes to my differing-length concerns so I suppose it’s a moot point.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334528" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-334528" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334528"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="334544" data-post-id="334544">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sodapopcan" data-post="16" data-topic="64915">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/48/34668_2.png" class="avatar"> sodapopcan:</div>
<blockquote>
<p>EDIT: I re-read the thread and had missed <a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a>’s message re: <code>filter_map</code> which I believe Elixir actually used to have?</p>
</blockquote>
</aside>
<p>And I was wondering why I can’t quickly find <code>filter_map</code>… It was last directly accessible in the docs all the way <a href="https://hexdocs.pm/elixir/1.4.5/Enum.html#filter_map/3" rel="noopener nofollow ugc">back in Elixir 1.4.5</a>, woah.</p>
<aside class="quote no-group" data-username="gregvaughn" data-post="15" data-topic="64915">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/48/954_2.png" class="avatar"> gregvaughn:</div>
<blockquote>
<p>The main piece to understand are filters in for comprehensions. If you have a clause that is not a generator, it’s a filter. If it evaluates to falsy, then the <code>do</code> block is <strong>not</strong> executed and the next iteration begins.</p>
</blockquote>
</aside>
<p>I understand the liking of the <code>for</code> comprehension and used it a lot but the whole truthy / falsy thing just rings my alarms as I am an other side of the spectrum and I want explicitness all the way to the point of ju-u-ust before it becomes unwieldy and annoying. To me the truthy / falsy semantics will be never welcome but oh well. Just adding one more anecdote because arguing for/against it is fruitless; it’s just a preference in the end, and it is clear that the core team is not on my side in this instance. I’ll just never ever approve of the <code>if value ...</code> thing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334544" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-334544" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334544"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="334568" data-post-id="334568">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pejrich" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pejrich/120/14576_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pejrich
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>But that’s why I guess I’m still confused by your point. You initially stated you get excited by <code>map</code>, but don’t like bloat. <code>map</code> is just <code>reduce</code> keeping all the elements.</p>
<blockquote>
<p>personally, i am quite happy with tools Elixir gives me already</p>
</blockquote>
<p>Ok, so if we look at something like <code>sum/1</code>. It can be implemented as simply as <code>reduce(list, &amp; &amp;1 + &amp;2)</code>. It’s also a function that only works on a list of a specific subset of types. There’s a number of functions that come in pairs like <code>uniq/1</code> and <code>uniq_by/2</code> where <code>uniq/1</code> could easily be called as <code>uniq_by(enum, &amp; &amp;1)</code>. There’s <code>max</code> and <code>min</code>, but also <code>min_max</code>(which of course could be achieved through <code>min</code> and <code>max</code>)</p>
<p>So your point is you don’t like bloat, but you like everything that’s currently in Elixir. So by what metric is <code>sum</code> and <code>uniq</code>, which have very simple implementations with <code>reduce</code> and <code>uniq_by</code>, not bloat? It seems like you define bloat as anything not currently in the language.</p>
<p>I’m not suggesting any of those functions <em>are</em> by my definition bloat, but it just seems like a confusing point to say “I don’t like bloat, everything currently in Elixir isn’t bloat, but we can’t compare anything because that’s too narrow”.</p>
<p>I agree with your statement that adding things for small wins will bloat the language, but I’m confused why you think <code>min_max</code> or <code>sum</code> provides value that couldn’t be achieved otherwise, but that anything else is bloat. Why is <code>min_max</code>(functionality already well served by <code>min</code> and <code>max</code>) more valuable than say <code>mean</code>/<code>median</code>/<code>mode</code>, something that’s a bit more complicated to implement with the current tools in <code>Enum</code>?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334568" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-334568" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334568"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="334570" data-post-id="334570">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="fmn" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fmn/120/26825_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  fmn
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>so, i am excited about stuff like <code>map</code>, <code>reduce</code> in general - they are pretty universal.<br>
i am not saying <code>map</code> on its own is enough to solve your case, but you can add stuff like <code>filter</code> to your recipe and you are probably good.</p>
<p>reg. “<em>I don’t like bloat, everything currently in Elixir isn’t bloat, but we can’t compare anything because that’s too narrow</em>” - let me put that this way: what i mean is that, adding your proposal to the language won’t make it slimmer or more elegant syntactically <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"> . if there is any bloat in Elixir, i don’t think it’s <code>map</code> or <code>reduce</code>.</p>
<p>btw. i appreciate you iterating over the matter, trying to get to the bottom of it. thank you!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334570" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-334570" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334570"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="334605" data-post-id="334605">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sodapopcan" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/120/34668_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sodapopcan
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m now seeing the bloat argument (I’m also very against bloat and am often loud about).</p>
<aside class="quote no-group" data-username="pejrich" data-post="18" data-topic="64915">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pejrich/48/14576_2.png" class="avatar"> pejrich:</div>
<blockquote>
<p>So by what metric is <code>sum</code> and <code>uniq</code></p>
</blockquote>
</aside>
<p>I think a good metric is what José mentioned: the question is “why do you need compact so often?”  Everyone once in a while we’re going to need to “compact” (which again I dislike the name even if it is understood generally) but does it really need to be codified?  On the other hand, <code>sum</code> and <code>uniq</code> are common needs and with super clear and expressive names… well, <code>uniq</code> could be spelled properly <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334605" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-334605" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334605"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="334751" data-post-id="334751">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pejrich" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pejrich/120/14576_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pejrich
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I also brought up the example of <code>min_max</code>. Is that something that is needed so often that calling <code>{Enum.min(list), Enum.max(list)}</code> became cumbersome? I’d say I need to remove nils from a list more often than I need <code>min_max</code>, and to implement <code>min_max</code> with the existing <code>min</code> and <code>max</code> functions is absurdly easy. Also I wasn’t suggesting there’s no need for <code>uniq</code>, merely that if the issue is bloat, <code>uniq_by(list, &amp; &amp;1)</code> is identical to <code>uniq</code>.</p>
<p>I’m not suggesting that anything needs to be removed from the language, but if the arguments against adding anything is bloat, it’s hard to say there’s not things in Enum already that are arguably bloat, yet they got approved.</p>
<p>The reason for needing compact, is because I would say there’s probably no other single value more frequently returned from an Elixir function than <code>nil</code>(<code>true</code>, and <code>false</code> might be the only other contenders). <code>nil</code> also happens to be a value that is quite often not needed when it’s in a list of other, non-nil values, hence the need to compact. Also I would agree that a <code>compact</code> function is likely bloat because it’s no different than <code>reject(&amp;is_nil/1)</code>. My proposal is only for a <code>compact_map</code> function that maps keeping only non-nils.</p>
<p>My argument for codifying it is because it more closely aligns with the way I logically think about that operation, and maybe others do too. If I’m mapping over a list of numbers, adding some value, then keeping anything greater than 5, that’s two clear logical steps in my head, a map, then a filter. But to me “for each item in the list, fetch the result of calling some function that’s not nil” is more how I think of it, than “fetch the result of the function for each item, then filter out the nils”. Surely a lot of the functions in <code>Enum</code> that can be implemented with other functions are there because they more closely align with how we think of something. <code>random</code> is probably how people think of fetching a random element, even if <code>list |&gt; shuffle() |&gt; List.first()</code> is functionally the same. Most people don’t think of a random item as being the first item of a shuffled list, they just think <code>get a random element</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="334751" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/addition-of-a-compact-map-2-function-to-the-enum-module/64915/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-334751" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="334751"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/64915/load_more?page=3">Load more posts (4 remaining)</a>
</div></template></turbo-stream>