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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="woohaaha" data-post="10" data-topic="41010">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/48.png" class="avatar"> woohaaha:</div>
<blockquote>
<ol>
<li>Errors falling through <code>with</code>. Then why use <code>with</code>?</li>
</ol>
</blockquote>
</aside>
<p>The simplest reason is that it lets you define a clear sequence of execution for functions that may fail without needing to nest conditional checks.</p>
<p>In the example you’re fetching a page (page may not exists), then authorizing the current user to interact with that page (user may not be authorized), then updating the page (update may be invalid).</p>
<p>You could nest three <code>if</code>s, “if page is not found fail, else if user is not authorized fail, else if page cannot be updated fail, else put flash and redirect”, but then all the error handling obscures what you’re actually trying to achieve.</p>
<p><code>with</code> allows you to structure it as “successfully get the page, then ensure the user is authorized, then update the page, then put flash and redirect”. That way the happy path is clear to see, but you haven’t ignored the fact that things can go wrong because you’re still checking for that, just not handling it right there.</p>
<aside class="quote no-group" data-username="woohaaha" data-post="10" data-topic="41010">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/48.png" class="avatar"> woohaaha:</div>
<blockquote>
<ol start="2">
<li>The first condition in the <code>with</code> is <code>page = CMS.get_page!(id)</code>, but if we don’t care about matching, why even put it in the <code>with</code>, it could well be outside, especially if it raises, which would make it even more clear. The <code>with</code> (to me) for <code>get_page!/1</code> is a bit of indirection.</li>
</ol>
</blockquote>
</aside>
<p>You could just as easily not put it in the <code>with</code>, but there’s a non-technical reason you might want to put it in there.</p>
<p>Since the <code>with</code> is defining the logic for some process, in this case how you update a page, and getting a page is a fundamental part of the process as they’re defining it, then including it in the <code>with</code> puts all the steps of the process at the same level so that it’s clear to understand each stage of the process.</p>
<p>It’s a decision entirely aimed towards trying to present something clearly for the developer, and it might not always be the clearest choice given a team’s conventions.</p>
<aside class="quote no-group" data-username="woohaaha" data-post="10" data-topic="41010">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/48.png" class="avatar"> woohaaha:</div>
<blockquote>
<ol start="3">
<li>The scope of <code>page</code> is then used in the <code>redirect</code>, how? (is that a mistype?)</li>
</ol>
</blockquote>
</aside>
<p>Everything defined between <code>with</code> and <code>do</code> is available in the <code>do</code> block (but not in the <code>else</code> block, if there is one), and if you reach the do block it means there were no errors before.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="219957" 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/why-was-equal-sign-used-in-with-statement/41010/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-219957" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="219957"
                     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="219960" data-post-id="219960">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="woohaaha" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  woohaaha
                    <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>Thank you everyone!!! <img src="https://forum.elixirforum.com/images/emoji/apple/clap.png?v=15" title=":clap:" class="emoji" alt=":clap:" loading="lazy" width="20" height="20">  <a class="mention" href="/u/bennelsonweiss" rel="nofollow">@bennelsonweiss</a> <a class="mention" href="/u/focused" rel="nofollow">@focused</a> <a class="mention" href="/u/sebb" rel="nofollow">@Sebb</a> <a class="mention" href="/u/felix-starman" rel="nofollow">@felix-starman</a></p>
<p>Such a nice implementation in the original example <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/blush.png?v=15" title=":blush:" class="emoji" alt=":blush:" 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="219960" 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/why-was-equal-sign-used-in-with-statement/41010/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-219960" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="219960"
                     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>