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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="fuelen" data-post="1" data-topic="75499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fuelen/48/9870_2.png" class="avatar"> fuelen:</div>
<blockquote>
<h4>Option 2. Explicit <code>:ext</code> namespace</h4>
<pre data-code-wrap="elixir"><code class="lang-elixir">{:string, min_length: 2, ext: [some_ext_opt: ...]}
</code></pre>
<p>Verbose, but core opts stay strictly typed. Everything inside <code>:ext</code> is <code>keyword()</code> and available to extensions. But feels a bit artificial, like a pattern grabbed from other programming languages where type system doesn’t allow anything else.</p>
</blockquote>
</aside>
<p>Disclaimer: I’m still learning, so not an Elixir expert.</p>
<p>This second option seems the best to me. Even if the type system can make sense of a big bag of atoms, having things namespaced like this makes things easier to reason about for everyone as long as it’s not nested imo.</p>
<p>Another option would be to allow the user to <em>register</em> their custom options with the lib via a macro, so that all options can be treated the same and verified at compile time by checking them against the list of registered atoms.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="389655" 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-is-the-idiomatic-shape-for-extensible-keyword-opts/75499/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-389655" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="389655"
                     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="389733" data-post-id="389733">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="fuelen" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fuelen/120/9870_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  fuelen
                      <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="mudasobwa" data-post="5" data-topic="75499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/48/5298_2.png" class="avatar"> mudasobwa:</div>
<blockquote>
<p>Correct me if I’m wrong, but you asked about the <em>idiomatic</em> solution. I honestly don’t know what would be more idiomatic than the language core. It accepts <code>keyword()</code> for convenience, but it <a href="https://github.com/elixir-lang/elixir/blob/v1.19.5/lib/elixir/lib/kernel.ex#L2461" rel="noopener nofollow ugc">immediately raises</a> when keys are not known.</p>
</blockquote>
</aside>
<p>Core doesn’t actually raise on unknown keys here. Both <code>inspect/2</code> and <code>String.split/3</code> just ignore them:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; inspect(1, my_option: 1)
"1"

iex&gt; String.split("Hello World", " ", test: 1)
["Hello", "World"]
</code></pre>
<p><code>custom_options</code> option was only added in 1.9.0. The struct itself existed long before that. A struct is not an open map by definition, so when the need for caller-supplied extras showed up, the only place to put them was a separate <code>custom_options</code> field. So I wouldn’t read it as evidence that the closed/struct approach is the idiomatic one. There wasn’t really a choice given the existing shape.</p>
<p><code>Logger</code> is in the standard library too, and it goes the other way from <code>Inspect.Opts</code>. It uses a single flat keyword for everything. Name collisions are possible, but they’re handled by convention and documentation, not by validation or a separate field.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Logger.info("hello", ansi_color: :green, whatever: 1)
</code></pre>
<aside class="quote no-group" data-username="lud" data-post="8" data-topic="75499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/48/14382_2.png" class="avatar"> lud:</div>
<blockquote>
<p>Don’t compromise correctness to save typing three characters, especially in the AI coding era. If a map is what you need then just use that.</p>
</blockquote>
</aside>
<p>That’s more about reading, rather than typing.<br>
I wouldn’t say map is correct in this case and keyword isn’t. Theoretically, there might be options in the future that’ll benefit from duplicate keys <img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="woylie" data-post="10" data-topic="75499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/woylie/48/38856_2.png" class="avatar"> woylie:</div>
<blockquote>
<p>And with shared options:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@type string_type :: :string | {:string, string_type_opt | shared_opt}
@type string_type_opt :: {:trim, boolean} | {:nilable, boolean} | ... | {:custom_options, keyword}
@type shared_opt :: {:something, boolean} | ...
</code></pre>
</blockquote>
</aside>
<p>You forgot about wrapping type to a list <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"> [EDIT: I misread shared options as open options and came to this example] With shared options it makes sense to use parameterized <code>open_keyword</code> type:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@type open_keyword(t) :: [t | {atom(), term()}]

@type string_option :: {:trim, boolean()} | ...
@type shared_option :: {:nilable, boolean()} | ...

@type string_type :: :string | {:string, open_keyword(string_option() | shared_option())}
</code></pre>
<p>Actually… it looks nice <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>
<aside class="quote no-group" data-username="GrammAcc" data-post="12" data-topic="75499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/grammacc/48/40380_2.png" class="avatar"> GrammAcc:</div>
<blockquote>
<p>Another option would be to allow the user to <em>register</em> their custom options with the lib via a macro, so that all options can be treated the same and verified at compile time by checking them against the list of registered atoms.</p>
</blockquote>
</aside>
<p>Yeah, I know <code>Req</code> library uses this approach. But Mold positions itself as a lightweight, shape-first library where schemas are plain data and ergonomics matter more than catching mistyped option names – <code>String.split/3</code> doesn’t check options and that’s not the end of the world.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="389733" 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-is-the-idiomatic-shape-for-extensible-keyword-opts/75499/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-389733" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="389733"
                     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="389736" data-post-id="389736">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="fuelen" data-post="13" data-topic="75499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fuelen/48/9870_2.png" class="avatar"> fuelen:</div>
<blockquote>
<p><code>custom_options</code> option was only added in 1.9.0.</p>
</blockquote>
</aside>
<p>Yeah, I am the author of the PR allowing custom options. AFAIR, my initial intent was to treat anything unknown as custom, but there was a rock-solid argument we should distinguish custom stuff and the expected one.</p>
<p>Also, <code>inspect/2</code> is a <code>Kernel</code> helper, I was talking about the protocol implementation.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="389736" 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-is-the-idiomatic-shape-for-extensible-keyword-opts/75499/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-389736" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="389736"
                     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>