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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Then I have no idea what you’re suggesting and how your suggestions can be represented in Elixir :\</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295055" 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/what-do-you-think-about-early-returns/56941/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-295055" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295055"
                     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 #31"></div>
  </section>
</div>
    <div class="postbit" id="295056" data-post-id="295056">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lpil" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lpil/120/17492_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lpil
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Gleam</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>A good example is the <code>lists</code> module. The programmer has an existing data type (a list) and we often need to perform familiar operations on it, such as locating an element in it, or removing elements that have some property. We could write these each time using recursion, or we could use the combinators found in the <code>lists</code> such as <code>search/2</code> and <code>filter/2</code> instead. The overhead of a function call is very small, so we can reduce the size of our code by not writing these by hand each time. In languages that compile to native this reduction in code size can even make programs faster! Though I do not know if this holds true for the BEAM.</p>
<p>The important detail for practical and performant functional combinators is to have them operate on the data structure you actually would be using otherwise, rather than to add meaningless extra wrappers which you would have to frequently allocate and then discard.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295056" 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/what-do-you-think-about-early-returns/56941/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-295056" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295056"
                     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 #32"></div>
  </section>
</div>
    <div class="postbit" id="295057" data-post-id="295057">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>First of all, how does <code>lists</code> solve anything related to control flow or early returns? There are monadic types which can be used to control flow, and I’ve just provided an example, but you’ve said that this was not what you were talking about. Second, Enum is a bad example, since it makes the code slower (like 20% slower), while it could be more performant if compiler could perform inter-module optimizations.</p>
<p>So, for types like <code>Either</code> or <code>Maybe</code> or <code>Option</code> (which are used for control flow in languages like Rust, Haskell, OCaml, etc) Elixir would be a very bad runtime.</p>
<p>The reason I am writing this is that I’ve seen this discussion many-many-many times, I’ve seen this idea being implemented in a few projects and every time it turned a disaster for performance and everybody just learned a lesson that these abstract ideas are inapplicable to dynamically typed languages without heavy compiler optimizations.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295057" 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/what-do-you-think-about-early-returns/56941/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-295057" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295057"
                     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 #33"></div>
  </section>
</div>
    <div class="postbit" id="295078" data-post-id="295078">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="lpil" data-post="19" data-topic="56941" 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/lpil/48/17492_2.png" class="avatar"> lpil:</div>
<blockquote>
<p>I’m surprised that there’s not any mention of function combinators such as <code>map</code> and <code>bind/try/then</code>, as is common in other functional languages. They can implement the same patterns as early returns but don’t require any special new language functionality, and they’re trivial for the programmer to extent. They work with pipes, or with a feature like Gleam’s <code>use</code> and OCaml’s <code>let</code> operators it can look very familiar too.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">pub fn reply(message) {
  use &lt;- guard(is_uppercase(message), return: Error(Rude))
  use &lt;- guard(message == "", return: Error(Quiet))
  use name &lt;- try(get_name())
  Ok("Hello, " &lt;&gt; name)
}
</code></pre>
</blockquote>
</aside>
<p>What are we missing there that can’t be done with <code>cond</code>, <code>case</code>, <code>with</code> and/or multiple function heads? My experience with things like bind is you had to read articles like <a href="https://fsharpforfunandprofit.com/posts/elevated-world-2/" rel="noopener nofollow ugc">this</a> to understand them, which you may or may not after reading that, and that, in my experience in F#, you need a library to wrap it to make it ergonomic.  It can end up being pretty clean with the computation expressions but if I translate this F#…</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">let almQueryProps objHandle =
    result {
        let! utc   = getProperty objHandle "DateTime"
        let! ms    = getProperty objHandle "MSeconds"
        let! value = getProperty objHandle "Value"
        return Int64.Parse(utc), Int32.Parse(ms), Int32.Parse(value)
    }
</code></pre>
<p>to Elixir…</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">with {:ok, utc} &lt;- get_property(obj_handle, "DateTime"),
     {:ok, ms} &lt;- get_property(obj_handle, "MSeconds"),
     {:ok, value} &lt;- get_property(obj_handle, "Value") do
  {String.to_integer(utc), String.to_integer(ms), String.to_integer(value)}
end
</code></pre>
<p>It is essentially the same but built into the language.  Having all those extra combinators and operators adds significant mental overhead.  For me, smashing out plain old boring functions and control flow is a lot easier to read and write.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295078" 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/what-do-you-think-about-early-returns/56941/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-295078" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295078"
                     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 #34"></div>
  </section>
</div>
    <div class="postbit" id="295128" data-post-id="295128">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lpil" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lpil/120/17492_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lpil
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Gleam</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cmo" data-post="35" data-topic="56941">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/48/19618_2.png" class="avatar"> cmo:</div>
<blockquote>
<p>What are we missing there that can’t be done with <code>cond</code>, <code>case</code>, <code>with</code> and/or multiple function heads?</p>
</blockquote>
</aside>
<p>Nothing in terms of early returns! In that respect they are equivalent. Elixir’s <code>with</code> and monadic interfaces are equivalent and can replace early returns here.</p>
<p>In the same way Elixir’s <code>for</code> is equivalent to certain list combinators such as <code>filter</code>, <code>map</code>, <code>flat_map</code>, and <code>fold</code>.</p>
<p>One thing that’s really nice about the combinator approach is that it can be used to implement functionality that other languages require keywords for. Take for example Go’s <code>defer</code> statement, which causes a function to be called after the scope has ended.</p>
<pre data-code-wrap="go"><code class="lang-go">func main() {
        file := file.Open(path)
        defer file.Close()

        // Use the file...
        doSomething(file)

        // file.Close() is called here
}
</code></pre>
<p>There’s no syntax for this in Elixir or Erlang, but we could write a function for it!</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def defer(first, then) do
  first()
after
  then()
end
</code></pre>
<p>And its usage:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def main() do
  file = File.open(path)
  defer(fn -&gt; File.close(file) end, fn -&gt; 
    do_something(file)
  end)
end
</code></pre>
<p>It’s a little less pretty in Elixir due to the syntax, but in other languages have syntax where they can use a combinator like this without the extra indentation.</p>
<p>Gleam:</p>
<pre data-code-wrap="gleam"><code class="lang-gleam">pub fn main() {
  let file = file.open(path)
  use &lt;- defer(fn() { file.close(file) })
  do_something(file)
}
</code></pre>
<p>Haskell, Elm, etc:</p>
<pre data-code-wrap="haskell"><code class="lang-haskell">main =
  let file = File.open path in
  defer (\-&gt; file.close file) \-&gt;
  doSomething file
</code></pre>
<p>Roc:</p>
<pre data-code-wrap="haskell"><code class="lang-haskell">main =
  file = File.open path
  _ &lt;- defer (\ -&gt; file.close file)
  doSomething file
</code></pre>
<p>This is really cool! With combinators functional languages can implement things that other languages might need special language support for, including those that may be awkward to represent with our usual trusty tools of <code>case</code>, <code>cond</code>, and <code>with</code>. More power for us! <img src="https://forum.elixirforum.com/images/emoji/apple/sparkles.png?v=15" title=":sparkles:" class="emoji" alt=":sparkles:" 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="295128" 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/what-do-you-think-about-early-returns/56941/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-295128" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295128"
                     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 #35"></div>
  </section>
</div>
    <div class="postbit" id="295131" data-post-id="295131">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="lpil" data-post="36" data-topic="56941">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lpil/48/17492_2.png" class="avatar"> lpil:</div>
<blockquote>
<p>There’s no syntax for this in Elixir or Erlang, but we could write a function for it!</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def defer(first, then) do
  first()
after
  then()
end
</code></pre>
</blockquote>
</aside>
<p>I can write such a function in any language that supports higher order functions (including golang), and actually if we talk in terms of implementations they are not equivalent, as you execute that code from context of a lambda, whereas in the golang this is a compiler eye candy that swaps those lines for you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295131" 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/what-do-you-think-about-early-returns/56941/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-295131" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295131"
                     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 #36"></div>
  </section>
</div>
    <div class="postbit" id="295144" data-post-id="295144">
  <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>Just curious, why would <code>defer</code> be preferable to a a higher order function, lambda, or block?  Maybe it’s the file handling example that’s tripping me up as it’s a well-known problem.  Are there scenarios where it would be better?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295144" 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/what-do-you-think-about-early-returns/56941/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-295144" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295144"
                     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 #37"></div>
  </section>
</div>
    <div class="postbit" id="295161" data-post-id="295161">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lpil" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lpil/120/17492_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lpil
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Gleam</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="D4no0" data-post="37" data-topic="56941">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/d4no0/48/33624_2.png" class="avatar"> D4no0:</div>
<blockquote>
<p>I can write such a function in any language that supports higher order functions (including golang)</p>
</blockquote>
</aside>
<p>That’s right! <em>Higher order functions</em> are the single requirement for <em>functional</em> combinators.</p>
<p>Go specifically struggles with them though as it only supports generic data structures, not generic methods.</p>
<aside class="quote no-group" data-username="D4no0" data-post="37" data-topic="56941">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/d4no0/48/33624_2.png" class="avatar"> D4no0:</div>
<blockquote>
<p>and actually if we talk in terms of implementations they are not equivalent, as you execute that code from context of a lambda, whereas in the golang this is a compiler eye candy that swaps those lines for you.</p>
</blockquote>
</aside>
<p>They won’t generate exactly the same machine code or bytecode (assuming a non-optimising compiler), but they are equivalent implementations. The only cost is a function call and a stack frame, very cheap! A good price for that much expressive power.</p>
<aside class="quote no-group" data-username="sodapopcan" data-post="38" data-topic="56941" 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/sodapopcan/48/34668_2.png" class="avatar"> sodapopcan:</div>
<blockquote>
<p>Just curious, why would <code>defer</code> be preferable to a a higher order function, lambda, or block? Maybe it’s the file handling example that’s tripping me up as it’s a well-known problem. Are there scenarios where it would be better?</p>
</blockquote>
</aside>
<p>I personally don’t think <code>defer</code> preferable to any of those, I picked it as a random language core feature that isn’t present in any of the functional languages I was using in my examples. Other examples could be:</p>
<p>async/await</p>
<pre data-code-wrap="rust"><code class="lang-rust">pub fn main() {
  use url &lt;- await(file.read(path))
  use response &lt;- await(http.get(url))
}
</code></pre>
<p>throw/catch</p>
<pre data-code-wrap="rust"><code class="lang-rust">pub fn main() {
  run(my_program, catch: io.debug)
}

pub fn my_program() {
  case something() {
    Ok(x) -&gt; return(x)
    Error(x) -&gt; throw(x)
  }
}
</code></pre>
<p>for comprehensions</p>
<pre data-code-wrap="rust"><code class="lang-rust">pub fn main() {
  use x &lt;- list.flat_map(xs)
  use y &lt;- list.map(ys)
  #(x, y)
}
</code></pre>
<p>generators</p>
<pre data-code-wrap="rust"><code class="lang-rust">pub fn my_generator() {
  use &lt;- yield(1)
  use &lt;- yield(2)
  use &lt;- yield(3)
  done()
}
</code></pre>
<p>Or anything else! Higher order functions are really cool and powerful in Elixir, Gleam, etc <img src="https://forum.elixirforum.com/images/emoji/apple/purple_heart.png?v=15" title=":purple_heart:" class="emoji" alt=":purple_heart:" 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="295161" 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/what-do-you-think-about-early-returns/56941/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-295161" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295161"
                     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 #38"></div>
  </section>
</div>
    <div class="postbit" id="295407" data-post-id="295407">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>What I love about functional programming is that it’s essentially just graph reduction (“everything is expression”), which makes reasoning about code much more simple. Early returns (as well as exceptions) throw this out of the window. If they are rather simulated with an elegant abstraction (e.g. Haskell’s <code>do</code>-notation for certain types, or Elixir’s <code>with</code>) then that’s fine because it’s still graph reduction.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295407" 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/what-do-you-think-about-early-returns/56941/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-295407" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295407"
                     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 #39"></div>
  </section>
</div>
    <div class="postbit" id="295408" data-post-id="295408">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Agree on using combinators. Sure the performance will suffer as there’s no free abstraction, but from my experience of working with a custom Algae-like library, it doesn’t really matter much even in code that’s mostly about iterating a lot of lists with close to no I/O, so the abstraction here is quite unlikely to become a bottleneck. Furthermore, abstraction also means centralizing implementation which in turn eases up potential optimization. As an example, consider the good old <code>map</code>: without it, your code will use a ton of slightly different manual recursive functions, and optimizing them one by one will be an enormous amount of work. With <code>map</code> though, you only need to optimize a single function. Sure, if performance is just critical to you, it might not be worth it to use a lot of combinators, especially the more advanced ones. But at this point, why use Elixir at all instead of a more performance oriented-language?<br>
However it’s also true that there’s no saving from the other cost of abstration – the struggle of learning it for the first time. And, given that Elixir as an ecosystem is not inherently welcoming of such thing, you’ll likely need to maintain your own library(ies) for them, which is an extra burden and an extra demand for experience with such things.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295408" 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/what-do-you-think-about-early-returns/56941/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-295408" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295408"
                     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 #40"></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/56941/load_more?page=5">Load more posts (10 remaining)</a>
</div></template></turbo-stream>