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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>instead of <code>Map.fetch(params, :shoes)</code></p>
</blockquote>
<blockquote>
<p><em>design patterns</em></p>
</blockquote>
<p>Following <a href="https://youtu.be/srQt1NAHYC0?t=200" rel="noopener nofollow ugc">Scott Wlaschin’s guidance</a> - <strong>use functions!</strong></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def fetch_item(map, key) do
  case Map.fetch(map, key) do
    :error -&gt;
      {:error, key}
    result -&gt;
      result
  end
end

  ...

  with(  
    {:ok, shoes} &lt;- fetch_item(outfit, :shoes),
    {:ok, shirt} &lt;- fetch_item(outfit, :shirt),
    {true, _} &lt;- {shoes_match_shirt?(shoes, shirt), :matching}
  ) do
    {:ok, "service allowed"}
  else
    {:error, :shoes} -&gt;
      {:error, "you forgot your shoes!"}
    _ -&gt;
      :error
  end

  ...
</code></pre>
<p>or</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def fetch_item(map, key, msg) when is_binary(msg) do
  case Map.fetch(map, key) do
    :error -&gt;
      {:error, msg}
    result -&gt;
      result
  end
end

  ...

  with(  
    {:ok, shoes} &lt;- fetch_item(outfit, :shoes, "you forgot your shoes!"),
    {:ok, shirt} &lt;- fetch_item(outfit, :shirt, "you forgot your shirt!"),
    {true, _} &lt;- {shoes_match_shirt?(shoes, shirt), :matching}
  ) do
    {:ok, "service allowed"}
  else
    {:error, msg} = msg_error when is_binary(msg) -&gt;
      msg_error
    _ -&gt;
      :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="91555" data-batch-url="/posts/batch_likers">
                        5
                      </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/with-1-design-patterns/15639/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-91555" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="91555"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="91569" data-post-id="91569">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="yourpalal" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  yourpalal
                    <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>Good point, that’s a very nice end result! I guess I still need to get a bit more into the functional zen of things! I’m looking forward to checking out that video later <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="91569" 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/with-1-design-patterns/15639/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-91569" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="91569"
                     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>