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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>First of all I think that this proposal has a lot of merit. Since a lot of the discussion as been around clarity I feel that a lot of that could be addressed through formatting of the additions.</p>
<p>Compare these two versions for example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for let {count, sum} = {0, 0}, i &lt;- [1, 2, 3] do
  sum = sum + i
  count = count + 1
  {i * 2, {sum, count}}
end
</code></pre>
<p>Or this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for let {count, sum} = {0, 0},
    i &lt;- [1, 2, 3] do
  sum = sum + i
  count = count + 1
  {i * 2, {sum, count}}
end
</code></pre>
<p>I feel like the latter addresses a lot of the clarity concerns and that style could be enforced through <code>mix format</code>.</p>
<hr>
<p>As a final note, we a possible alternative to <code>for let</code> could be <code>for with</code> but that could have some connotation collisions with <code>with</code>. On the other hand it reads nicely.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for with {count, sum} = {0, 0},
    i &lt;- [1, 2, 3] do
    sum = sum + i
    count = count + 1
    {i * 2, {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="239783" 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/113">Post #112</a>
	                </div>
	            </div>
              <div id="likers-container-239783" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239783"
                     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 #112"></div>
  </section>
</div>
    <div class="postbit" id="239816" data-post-id="239816">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>FWIW, take a look at the etran parse transform library that introduced fold and indexed list comprehensions to Erlang:</p>
<p><a href="https://github.com/saleyn/etran#listcomp-fold-and-indexed-list-comprehensions" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/saleyn/etran#listcomp-fold-and-indexed-list-comprehensions</a></p>
<p>Somewhat similar goals, albeit different more succinct syntax.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="239816" 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/114">Post #113</a>
	                </div>
	            </div>
              <div id="likers-container-239816" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239816"
                     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 #113"></div>
  </section>
</div>
    <div class="postbit" id="239882" data-post-id="239882">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Qqwy" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Qqwy/120/1349_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Qqwy
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>TypeCheck Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/josevalim" rel="nofollow">@josevalim</a> How will the new constructs desugar? Will the new constructs be able to compile to efficient bytecode, or are there gotcha’s?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="239882" 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/115">Post #114</a>
	                </div>
	            </div>
              <div id="likers-container-239882" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239882"
                     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 #114"></div>
  </section>
</div>
    <div class="postbit" id="239900" data-post-id="239900">
  <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">
								<p>They should desugar to nested reduces, which is how most comprehensions desugar today (with the exception of <code>into: ""</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="239900" 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/116">Post #115</a>
	                </div>
	            </div>
              <div id="likers-container-239900" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239900"
                     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 #115"></div>
  </section>
</div>
    <div class="postbit" id="240091" data-post-id="240091">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="sasajuric" data-post="102" 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/sasajuric/48/991_2.png" class="avatar"> sasajuric:</div>
<blockquote>
<p>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>
</blockquote>
</aside>
<p>That’s how I read it too. I share the same feeling about the topic. It’s like <code>map</code> is the default “behaviour” of <code>for</code> and you can modify that. And, once one learns that <code>for</code> can behave like <code>map_reduce</code>, you don’t need to explain every other possible behavior. It’s more intuitive.</p>
<p>I was thinking about suggesting <code>having</code> instead of <code>let</code>. But, to be honest, I’m more concerned about the return of the block than about <code>let</code> itself. With <code>for map_reduce</code>, everything makes sense.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="240091" 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/117">Post #116</a>
	                </div>
	            </div>
              <div id="likers-container-240091" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="240091"
                     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 #116"></div>
  </section>
</div>
    <div class="postbit" id="242016" data-post-id="242016">
  <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">
								<p>My use case: send push notifications to all of user’s devices from an Oban job; the job succeeds if the notification reached at least one device or there were no errors; a device may become invalid due to token expiry, but that’s neither a success nor an error. This could look something like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for &lt;FOO&gt; {sent, error} = {false, nil},
          device &lt;- devices do
  case PushNotifications.push(device.id, content, data) do
    :ok -&gt; {true, error}
    {:error, :invalid_device} -&gt; {sent, error}
    {:error, reason} -&gt; {sent, reason}
  end
after
  {true, _error} -&gt; :ok
  {false, nil} -&gt; :ok
  {_sent, error} -&gt; {:error, error}
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="242016" 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/118">Post #117</a>
	                </div>
	            </div>
              <div id="likers-container-242016" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="242016"
                     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 #117"></div>
  </section>
</div>
    <div class="postbit" id="250797" data-post-id="250797">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I welcome this proposal. While I understand there are concerns about bloat, there are two reasons think it’s still worth it:</p>
<ul>
<li>The expressiveness it adds would have high impact. There are many situations where you can collapse a bunch of <code>Enum</code> expressions or <code>def</code> clauses with pattern matching into a simpler <code>for</code> expression.</li>
<li>Because this is a sub-feature of <code>for</code>, it doesn’t have far-reaching impact on the language</li>
</ul>
<p>I like the <code>let</code> keyword and don’t think “thinking this is mutable” should be a concern. Before someone is able to use <code>for</code>, they would have to (1) learn the fundamentals of Elixir <em>including</em> immutability and (2) read the documentation to understand how <code>for</code> works.</p>
<p>So I would optimize for making <code>for let</code> and <code>for reduce</code> being intuitive once you learn about them.</p>
<p>While I find the return value of <code>for reduce</code> intuitive (just return the accumulator), I find the <code>for let</code> return value less intuitive.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="250797" 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/119">Post #118</a>
	                </div>
	            </div>
              <div id="likers-container-250797" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="250797"
                     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 #118"></div>
  </section>
</div>
    <div class="postbit" id="273798" data-post-id="273798">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="yolo007wizard" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  yolo007wizard
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Found this thread along my learning journey. I am very new to Elixir coming from Python land so I’ll share my fresh rookie observations:</p>
<ul>
<li>one of the first things I found confusing/difficult in Elixir was traversing nested structures.</li>
<li>on reddit and in forum here I saw lots of people using Enum with pipes for everything</li>
<li>I was amazed after reading the comprehensions guide and confused why it seems unpopular (inferred from forum comments). For loops feel more natural than Enum coming from Python. Plus if I need a for loop inside a pipe I think I’d use an anonymous function. Maybe thats bad but it feels more readable than a long Enum.</li>
</ul>
<p>With that said I’m all in favour of powering up the for comprehension. Personally I liked this naming the best:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for init(sum = 0), x &lt;- [1, 2, 3] do
  {x * 2, sum + x}
end
</code></pre>
<p>Also it doesn’t bother me that it can have different return types. The comprehension is already unique to other langs so its not a big deal imo to add one more characteristic. Once you know, you know, you know?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="273798" 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/120">Post #119</a>
	                </div>
	            </div>
              <div id="likers-container-273798" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="273798"
                     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 #119"></div>
  </section>
</div>
    <div class="postbit" id="273833" data-post-id="273833">
  <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 agree that comprehensions are generally underused in Elixir, but I also understand the resistance.  Using the “coming from” argument (which I never like, and I’m not trying to be snarky here), the large majority of Elixir users are coming from either functional languages or Ruby.  While some functional languages have comprehensions, none of them push you to use them as much as Python does.  I think this is for a very good reason too—comprehensions can be super concise and powerful in many situations, but there are also many situations where a pipeline of transformations is going to read much clearer (I am, of course, just paraphrasing what is stated in the Problem Statement way above).</p>
<p>While I’m speaking absolutes there, I should say that this is my theory as why there is perceived resistance.  I could be wrong.</p>
<p>That said, since I never weighed in before, I’m all for this proposal, and I’m on Team <code>for let</code>.  I generally prefer pipelines but I do have a distaste for <code>reduce</code>.  This is due to <code>reduce</code> being the primitive that every other iterator is built on and therefore just reading its name tells me very little about what I’m going to get back.  With higher level iterators there are even many small cases I can get away with not even reading their bodies because I know don’t particularly care about that step of the pipeline, I just see <code>map</code> and know each element is being transformed <em>somehow</em>.  This is really great for efficient code skimming.  If I find myself reaching for reduce I always try and think how I could do it without, and when I find I do actually do need it I’m kinda like, “Oh, cool!”  But then, I’d still rather use a comprehension or even recursion.</p>
<p>Anyway, this turned into a rant and was longer than I meant it to be.  I was sorta happy to see this thread pop up again because I was wondering where things are at with it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="273833" 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/121">Post #120</a>
	                </div>
	            </div>
              <div id="likers-container-273833" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="273833"
                     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 #120"></div>
  </section>
</div>
    <div class="postbit" id="273844" data-post-id="273844">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I know I’m bikeshedding but I just hate “let”.  It introduces a new quasi-keyword, it’s not <em>quite</em> used in the same way as other langs: JS, rust, BASIC, so it’s going to be super confusing.  I think we have the correct “keyword” in <code>bind</code> (like :bind_quoted), but the syntax will have to be ever so slightly different, not quite sure what exactly is right. I think it’s worth it for the core team to think hard about what makes the most sense to give the highest consistency with what already exists.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="273844" 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/122">Post #121</a>
	                </div>
	            </div>
              <div id="likers-container-273844" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="273844"
                     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 #121"></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=13">Load more posts (3 remaining)</a>
</div></template></turbo-stream>