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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="derekbrown" data-post="92" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/derekbrown/48/19284_2.png" class="avatar"> derekbrown:</div>
<blockquote>
<p>I’ll refrain from responding to the “superficial” statement.</p>
</blockquote>
</aside>
<p>Just to expand on this a little more… I personally don’t think that the correlation would be easier for beginners because guards syntax is already well-defined in elixir by using the <code>when</code> keyword. Also, is not usual to use guards with functions that don’t return a boolean value (if I’m not mistaken, but I might be wrong on this). So, it seems that instead of “similar to guards”, it’s just ‘qualifiers’ in a different position.</p>
<aside class="quote no-group" data-username="derekbrown" data-post="92" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/derekbrown/48/19284_2.png" class="avatar"> derekbrown:</div>
<blockquote>
<p>There’s no reason why an <code>init</code> “guard” couldn’t be used in other scopes. I could certainly see it being useful outside of comprehensions</p>
</blockquote>
</aside>
<p>Could you elaborate on other use cases you’ve thought would be useful (similarly to the proposed usage, at least)? One of the concerns brought up in previous discussions was that ‘qualifiers’ were strange and specific to <code>for</code> and not commonly seen in other parts of the language like I said.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237348" 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/introducing-for-let-and-for-reduce/44773/93">Post #92</a>
	                </div>
	            </div>
              <div id="likers-container-237348" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237348"
                     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 #92"></div>
  </section>
</div>
    <div class="postbit" id="237353" data-post-id="237353">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="thiagomajesk" data-post="93" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thiagomajesk/48/31904_2.png" class="avatar"> thiagomajesk:</div>
<blockquote>
<p>So, it seems that instead of “similar to guards”, it’s just ‘qualifiers’ in a different position.</p>
</blockquote>
</aside>
<p>Guards are a qualifier in the position that I’m referencing. That’s the analog.</p>
<blockquote>
<p>Could you elaborate on other use cases you’ve thought would be useful (similarly to the proposed usage, at least)?</p>
</blockquote>
<p>One example, when piping into conditionals like <code>case</code>/<code>cond</code>, it could be nice to have additional data there with the conditional itself, rather than “init-ing” values above the pipe chain. Could possibly also be used in the function head as a more explicit default for recursive functions.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237353" 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/introducing-for-let-and-for-reduce/44773/94">Post #93</a>
	                </div>
	            </div>
              <div id="likers-container-237353" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237353"
                     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 #93"></div>
  </section>
</div>
    <div class="postbit" id="237376" data-post-id="237376">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That’s something I’ve thought would be useful to add to for comprehensions (I actually <a href="https://github.com/brettbeatty/stream_comprehension_elixir" rel="noopener nofollow ugc">hacked on a macro for this recently</a>). In my mind it makes comprehensions more composable–you can pass the comprehension streams into additional comprehensions or Enum/Stream functions without many traversals of your list. I see stream comprehensions as the <code>Ecto.Query.from/2</code> macro if the Stream module is the rest of <code>Ecto.Query</code> (hopefully that makes sense).</p>
<p>I think in this discussion folks are more looking for a way to reduce without leaving <code>for</code>, but I like the idea of being able to mix &amp; match.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237376" 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/introducing-for-let-and-for-reduce/44773/95">Post #94</a>
	                </div>
	            </div>
              <div id="likers-container-237376" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237376"
                     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 #94"></div>
  </section>
</div>
    <div class="postbit" id="237427" data-post-id="237427">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="83" data-topic="44773" 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/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>My thoughts on this topic have changed several times but right now I am closer to <code>for_let</code> and <code>for_reduce</code> than <code>for let</code>. The reason is simple: different return types should have different functions.</p>
</blockquote>
</aside>
<p>Agreed on this a lot! I particularly don’t like how Ecto’s <code>Repo.transaction</code> changes behaviour based on whether you’re passing a function or a <code>Multi</code>. Unless there’s something I’m missing, there should be <code>Multi.transaction(multi)</code> instead of <code>Repo.transaction(multi)</code> (or maybe <code>Multi.run</code> to mirror <code>Stream.run</code> except that <code>Multi.run</code> is already a thing).</p>
<p>I’d prefer <code>for let</code> and even <code>forlet</code> instead of <code>for_let</code>. While those are all macros or special forms, there are some constructs that are treated as “keywords” (<code>defmodule</code>, <code>for</code>, <code>while</code>, <code>if</code>, etc.). Somehow <code>for_let</code> doesn’t fit in there.</p>
<p>But… another approach to solving this would be to declare the shape of the returned value in the <code>for</code>’s “header”. Also, thinking about this more, <code>reduce</code> is not friendly to people coming from imperative languages. I think talking about the “returned value” is way more familiar, so I’m also proposing to get rid of <code>reduce</code> altogether in favour of <code>return</code>.</p>
<p>So a map-reduce would be:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for return {sum = 0, count = 0, i &lt;- [1, 2, 3]} do
  sum = sum + 1
  count = count + 1
  {sum, count, i}
end
</code></pre>
<p>and reduce:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for return {sum = 0, count = 0}, i &lt;- [1, 2, 3] do
  sum = sum + 1
  count = count + 1
  {sum, count}
end
</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="237427" 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/introducing-for-let-and-for-reduce/44773/96">Post #95</a>
	                </div>
	            </div>
              <div id="likers-container-237427" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237427"
                     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 #95"></div>
  </section>
</div>
    <div class="postbit" id="237434" data-post-id="237434">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                    <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 class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="stefanchrobot" data-post="96" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stefanchrobot/48/7657_2.png" class="avatar"> stefanchrobot:</div>
<blockquote>
<p>But… another approach to solving this would be to declare the shape of the returned value in the <code>for</code>’s “header”.</p>
</blockquote>
</aside>
<p>I have considered this route but I can’t come up with any reasonable syntax. Putting the generator as part of the return type feels incorrect, the generator is not really part of the result and you can have multiple generators, which would not make sense either. We would need a way to refer to the output but all of them would feel magical.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237434" 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/introducing-for-let-and-for-reduce/44773/97">Post #96</a>
	                </div>
	            </div>
              <div id="likers-container-237434" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237434"
                     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 #96"></div>
  </section>
</div>
    <div class="postbit" id="237436" data-post-id="237436">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="97" data-topic="44773" 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/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Putting the generator as part of the return type feels incorrect, the generator is not really part of the result and you can have multiple generators, which would not make sense either. We would need a way to refer to the output but all of them would feel magical.</p>
</blockquote>
</aside>
<p>I think that the following would make sense, except that I’m not sure what should be done with pattern matching.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for i &lt;- [1, 2, 3], return {sum = 0, count = 0, i} do
  sum = sum + 1
  count = count + 1
  {sum, count, i}
end
</code></pre>
<p>Flipping the order <em>maybe</em> would solve that by “enforcing” to bind to a variable:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for return {sum = 0, count = 0, i}, &lt;some pattern&gt; = i &lt;- [1, 2, 3],  do
  sum = sum + 1
  count = count + 1
  {sum, count, i}
end
</code></pre>
<p>Did you consider a <code>return</code>-like macro inside the block? I know that some options have been dismissed on the mailing list due to “refactorability” of the code, but to me this seems similar to rolling back Ecto transactions - there is some minimal amount of plumbing/wiring needed:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Repo.transaction(fn -&gt;
  # ...
  # do stuff, but at some point:
  |&gt; case do
    {:ok, foo} -&gt; foo
    {:error, reason} -&gt; Repo.rollback(reason)
  end
end)
</code></pre>
<p>So how about something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for i &lt;- [1, 2, 3], sum = 0, count = 0 do
  sum = sum + 1
  count = count + 1
  continue {i, sum, count}
end
</code></pre>
<p>I guess I’m starting to lean towards something like <code>after</code> from the initial proposal, but maybe more of a single expression than imperative rebindings.</p>
<p>EDIT: <code>after</code> would work too, but <code>continue</code> would be best for people from imperative background:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for i &lt;- [1, 2, 3], sum = 0, count = 0 do
  sum = sum + 1
  count = count + 1
after
  {i, sum, count}
end
</code></pre>
<p>If we had <code>continue</code> I’d love to see <code>break</code> for early exits.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237436" 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/introducing-for-let-and-for-reduce/44773/98">Post #97</a>
	                </div>
	            </div>
              <div id="likers-container-237436" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237436"
                     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 #97"></div>
  </section>
</div>
    <div class="postbit" id="237437" data-post-id="237437">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I feel like <code>for</code> is already an odd construct, because it behaves like a Enum.map (with nesting and filtering). Ideally I think you’d want generators to be more integrated with the standard library, but that’s hard to do right now.</p>
<p>To avoid confusion, I would let the <code>for</code> contruct mirror the functions we know as much as possible, instead of making up new terms for the same functions we already have in Enum.</p>
<p>Something like this (map can be the default unless specified):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for map x &lt;- [1,2,3], y &lt;- [4,5,6] do
  {x, y}
end

for map_reduce acc = 0, x &lt;- [1,2,3], y &lt;- [4,5,6] do
  {{x, y}, acc + x + y}
end

for reduce acc = 0, x &lt;- [1,2,3], y &lt;- [4,5,6] do
  acc + x + y
end
</code></pre>
<p>This will also leave some room for possible future expansion for any other enumerable functions.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237437" data-batch-url="/posts/batch_likers">
                        20
                      </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/introducing-for-let-and-for-reduce/44773/99">Post #98</a>
	                </div>
	            </div>
              <div id="likers-container-237437" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237437"
                     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 #98"></div>
  </section>
</div>
    <div class="postbit" id="237467" data-post-id="237467">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is a neat idea, I like how explicit and intuitive to understand it is!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237467" 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/introducing-for-let-and-for-reduce/44773/100">Post #99</a>
	                </div>
	            </div>
              <div id="likers-container-237467" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237467"
                     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 #99"></div>
  </section>
</div>
    <div class="postbit" id="237576" data-post-id="237576">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="1" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>You could move the initialization of the let variables to before the comprehension:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; sum = 0
iex&gt; count = 0
iex&gt; for let {sum, count}, i &lt;- [1, 2, 3] do
...&gt;   sum = sum + i
...&gt;   count = count + 1
...&gt;   {i * 2, {sum, count}}
...&gt; end
{[2, 4, 6], {6, 3}}
</code></pre>
<p><code>let</code> can be a variable or a tuple of variables. If the variables are not initialized, it is expected for such variable to already exist, as in the example above.</p>
</blockquote>
</aside>
<p>I don’t like this part. I think making initialization explicit reads better:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; for let {sum, count} = {sum_var, count_var}, 
...&gt;   i &lt;- [1, 2, 3] do
...&gt;     sum = sum + i
...&gt;     count = count + 1
...&gt;     {i * 2, {sum, count}}
...&gt; end
{[2, 4, 6], {6, 3}}
</code></pre>
<p>Generally, adding this to comprehensions is nice. Kudos!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237576" 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/introducing-for-let-and-for-reduce/44773/101">Post #100</a>
	                </div>
	            </div>
              <div id="likers-container-237576" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237576"
                     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 #100"></div>
  </section>
</div>
    <div class="postbit" id="237598" data-post-id="237598">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sasajuric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/120/991_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sasajuric
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Elixir In Action</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="fidr" data-post="99" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fidr/48/16811_2.png" class="avatar"> fidr:</div>
<blockquote>
<p>Something like this (map can be the default unless specified):</p>
</blockquote>
</aside>
<p>This is exactly how I feel about this topic. I like that <code>for</code> is getting <code>map_reduce</code> capabilities, but I dislike the <code>let</code> name. First, it introduces a completely new terminology for something we already have. But more importantly, this terminology misses the main purpose of such comprehension (to map and accumulate). So from that standpoint, <code>for map</code> (same as plain <code>for</code> for backwards compatibility), together with <code>for reduce</code> and <code>for map_reduce</code> seem perfect to me.</p>
<p>I don’t share the interpretation that <code>for</code> means map. To me a construct like <code>for x &lt;- 1..3, x != 2, ...</code> always reads as “for every x in 1..3, x not equals 2, … do something”. In other words, IMO the word for communicates about the traversal, not about the outcome of such traversal.</p>
<p>For completeness, I also privately proposed three separate special forms: <code>map</code> (current for), <code>reduce</code>, and <code>map_reduce</code>. However, José pointed out that this would break a lot of the existing code. Perhaps if Elixir was designed from the ground up that would make sense, but as it is, <code>for map</code>, <code>for reduce</code>, and <code>for map_reduce</code> are the options I like the best, both as the user of the language, but also as a mentor and a book author who will have to explain this stuff to other people <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="237598" data-batch-url="/posts/batch_likers">
                        36
                      </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/introducing-for-let-and-for-reduce/44773/102">Post #101</a>
	                </div>
	            </div>
              <div id="likers-container-237598" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237598"
                     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 #101"></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/44773/load_more?page=11">Load more posts (23 remaining)</a>
</div></template></turbo-stream>