<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="243733" data-post-id="243733">
  <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">
								<p>Your example is parsing and you are essentially hiding the parse errors. Is Option not the absence of something? Wouldn’t a Result be a better fit here?</p>
<p>What’s the advantage over using <code>with</code> or changesets in this context?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="243733" 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/option-type-compatible-with-comprehensions-in-elixr/46077/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-243733" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="243733"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="243745" data-post-id="243745">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="21" data-topic="46077">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">    if valid_index?(bracket_open_index) do
      raw_show
      |&gt; String.slice(0..(bracket_open_index - 1))
      |&gt; String.trim()
      |&gt; Option.new()
    else
      Option.new()
    end
</code></pre>
</blockquote>
</aside>
<p>Having <code>Option.new</code> be used both for success and error is non-intuitive. For readability just have constructors for each variant: <code>Option.some(value)</code> and <code>Option.none()</code>.</p>
<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="21" data-topic="46077">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">    for year_str &lt;- parse_year_start(bracket_open, dash, raw_show),
        year &lt;- StringHelpers.to_int_maybe(year_str),
        into: Option.new() do
      year
    end
</code></pre>
</blockquote>
</aside>
<p>You are trying very hard to use <code>for</code> here for no good reason IMO. Having a <code>with</code> statement with several parsing / validation steps that returns <code>Option.none()</code> should any of them fail and only returns <code>Option.some(year)</code> if they all succeed is more readable, I believe.</p>
<p>Not to mention that you could eliminate most of your hand-rolled parsing code if you use <code>nimble_parsec</code>. <img src="https://forum.elixirforum.com/images/emoji/apple/person_shrugging.png?v=15" title=":person_shrugging:" class="emoji" alt=":person_shrugging:" loading="lazy" width="20" height="20"></p>
<hr>
<p>I guess it all boils down to these questions: is the code supposed to be read by somebody else, ever? Is it only for your satisfaction and to exercise and gauge the validity of your idea? If so, then by all means, do continue. <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" 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="243745" 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/option-type-compatible-with-comprehensions-in-elixr/46077/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-243745" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="243745"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="243762" data-post-id="243762">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <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">
								<aside class="quote no-group" data-username="cmo" data-post="23" data-topic="46077">
<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>Your example is parsing and you are essentially hiding the parse errors. Is Option not the absence of something? Wouldn’t a Result be a better fit here?</p>
</blockquote>
</aside>
<p>The Option type is not meant to tell you about errors, it is meant to discard them.<br>
A Result/Error Monad would be a better fit if you want o know exactly what failed and why.</p>
<p>If you are confused as to what these types are supposed to be, I recommend a series:</p>
<ul>
<li><a href="https://www.youtube.com/watch?v=t1e8gqXLbsU" rel="noopener nofollow ugc">https://www.youtube.com/watch?v=t1e8gqXLbsU</a></li>
</ul>
<p>This example was always only focused on the Option type. Discussing the Result type is out of scope as I don’t have an implementation to make comparisons.</p>
<hr>
<p><a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a> Your opinion in the API has some merit. However, I decided the follow the same model as Witchcraft does, as I find it very user friendly. I guess it comes down to personal taste. If you invoke <code>Option.new</code> with a value, you get <code>Some</code> and if not, you get <code>None</code>.  Alternatively, you can use the structs themselves as returns <code>Option.Some...</code> or <code>Option.None</code>. You have the choice if you want to go down that route. I just figured that a <code>Option.new</code> was simple enough.</p>
<p>In regards to your personal opinion in relation to the validity of this approach, we can have this discussion in another place (if you insist on having. I personally don’t).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="243762" 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/option-type-compatible-with-comprehensions-in-elixr/46077/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-243762" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="243762"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="244078" data-post-id="244078">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><em>Please note some posts have been edited/removed to clean up the thread following OP’s request to remove the contentious part of their post.</em></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="244078" data-batch-url="/posts/batch_likers">
                        4
                      </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/option-type-compatible-with-comprehensions-in-elixr/46077/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-244078" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="244078"
                     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>