<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="264172" data-post-id="264172">
  <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>The real issue to understand here is immutability. <code>Enum.each</code> <em>always</em> returns <code>:ok</code> and it has no access to variables outside of its scope, so there is no use in assigning to a var within a function passed to <code>Enum.each</code>. As you gain more experience in functional style programming, you’ll start thinking in higher-order functions. Those are great building blocks that can be combined in many ways to make your exercise clear and concise (to those familiar with functional style). Here’s two ways I’d solve it:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(63)&gt; list1 = [
...(63)&gt;            [1 ,2,3,4,"nil"],
...(63)&gt;            [6,7,8,9,10,],
...(63)&gt;            [11,"nil",13,"nil",15],
...(63)&gt;            [16,17,"nil",19,20] ]
[
  [1, 2, 3, 4, "nil"],
  [6, 7, 8, 9, 10],
  [11, "nil", 13, "nil", 15],
  [16, 17, "nil", 19, 20]
]
iex(64)&gt; Enum.flat_map(list1, fn row -&gt; Enum.filter(row, &amp;(&amp;1 in 10..20)) end)
[10, 11, 13, 15, 16, 17, 19, 20]
iex(65)&gt; for row &lt;- list1, elt &lt;- row, elt in 10..20, do: elt
[10, 11, 13, 15, 16, 17, 19, 20]
</code></pre>
<p>In the first example, I’ve combined two higher-order functions (flat_map and filter) with an anonymous function (invoking the <code>in</code> operator). The second is a for comprehension, which is more advanced. It should not be confused with a for loop. Comprehensions are much more powerful.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="264172" data-batch-url="/posts/batch_likers">
                        2
                      </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/itertating-a-2d-matrix/50849/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-264172" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="264172"
                     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="264259" data-post-id="264259">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Even in Python, this should have been using reduce().</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="264259" 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/itertating-a-2d-matrix/50849/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-264259" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="264259"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>