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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="axelson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/axelson/120/26351_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  axelson
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Scenic Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="JoeZMar" data-post="7" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joezmar/48/11738_2.png" class="avatar"> JoeZMar:</div>
<blockquote>
<p>What’s considered a big enumerable? The map I was trying to Enumerate over has 5 keys and each had an empty list except one.</p>
</blockquote>
</aside>
<p>There’s no set rule but I would think you’d want a total of 200 or so items over those 5 keys before it makes sense performance wise to move to a different data structure. But actually analyzing the performance is always best.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="113655" 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/enum-member-in-a-map-with-multiple-lists/19772/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-113655" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="113655"
                     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="113656" data-post-id="113656">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JoeZMar" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JoeZMar/120/11738_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JoeZMar
                    <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>The GenServer holding onto the ids has a few other jobs related to its purpose and the ids are very temporary and have no chance of changing in the future. If I am using two GenServers, mostly for the purpose of organization (one is responsible for the browser actions and the other is for delegating tasks needed to specific users). I have a Postgres db that ultimately stores the items that get picked up and by which users.</p>
<p>I am trying to move my state away from the boundaries of my app (funneling everything into a db) and using the BEAM more with things like GenServers, <code>:ets</code>, and even <code>mnesia</code>. So what would the difference between storing ids of users searching for items within a GenServer versus storing it within an <code>:ets</code> table?</p>
<p>I was just breaching a more advanced rails position when I left and began learning Elixir for my own projects. I do wish that I had more experience when I made the transition because building Rails apps finally started to seem easy then I abruptly changed to Elixir. I feel like l can see more of the bigger picture this time, but I’m still working out the kinks that really slow me down. I love OTP, I just have to figure it out. <img src="https://forum.elixirforum.com/images/emoji/apple/joy.png?v=15" title=":joy:" class="emoji" alt=":joy:" loading="lazy" width="20" height="20"></p>
<p>Edit: The other thing I want to note, there will be a user scraping the page and checking against the state in the GS once to several times a second.</p>
<p>I also chose Hound because the site is 100% javascript. It’s a tiny app, but does not work without it. I’ve only deconstructed one other site using MITM once before and didn’t know how I could simulate the same things.</p>
<p>I would also be willing to pay someone to help me build the rest of an app to further understand Elixir. I really want to start contributing to the community, but I’m just not quite there yet.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="113656" 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/enum-member-in-a-map-with-multiple-lists/19772/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-113656" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="113656"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="113662" data-post-id="113662">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="idi527" data-post="2" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/i/85e7bf/48.png" class="avatar"> idi527:</div>
<blockquote>
<p>In short my way is basically easier to modify on everyone’s needs.</p>
</blockquote>
</aside>
<p>It doesn’t work on structs though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="113662" 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/enum-member-in-a-map-with-multiple-lists/19772/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-113662" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="113662"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="113663" data-post-id="113663">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JoeZMar" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JoeZMar/120/11738_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JoeZMar
                    <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>This is what I just realized. It was the struct that put a kink in it for me. When I start my GS I initialize it with a map with the 5 values with empty lists now and it seems to work.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="113663" 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/enum-member-in-a-map-with-multiple-lists/19772/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-113663" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="113663"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="113664" data-post-id="113664">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="JoeZMar" data-post="13" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joezmar/48/11738_2.png" class="avatar"> JoeZMar:</div>
<blockquote>
<p>I have a Postgres db that ultimately stores the items that get picked up and by which users.</p>
</blockquote>
</aside>
<p>It explains everything. You have all you need to create a relation like I described already.</p>
<aside class="quote no-group" data-username="JoeZMar" data-post="13" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joezmar/48/11738_2.png" class="avatar"> JoeZMar:</div>
<blockquote>
<p>I am trying to move my state away from the boundaries of my app (funneling everything into a db) and using the BEAM more with things like GenServers, <code>:ets</code> , and even <code>mnesia</code> . So what would the difference between storing ids of users searching for items within a GenServer versus storing it within an <code>:ets</code> table?</p>
</blockquote>
</aside>
<p>If you have <code>PostgreSQL</code> database already then you do not need extra database. It only complicates your code. I was thinking about <code>SQLite 3</code> (single file database) or <code>:mnesia</code> (which stores data in directory) for simplicity i.e. no need to setup database somewhere in <code>/var/</code> or something like that. For example <code>:mnesia</code> is builtin in <code>Erlang</code>, so there is no need to install something like <code>PostgreSQL</code>. Everything changes if you already have database. Relation like I described is good, because it’s easy to extend (just by adding some extra fields).</p>
<aside class="quote no-group" data-username="JoeZMar" data-post="13" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joezmar/48/11738_2.png" class="avatar"> JoeZMar:</div>
<blockquote>
<p>I also chose Hound because the site is 100% javascript. It’s a tiny app, but does not work without it. I’ve only deconstructed one other site using MITM once before and didn’t know how I could simulate the same things.</p>
</blockquote>
</aside>
<p>This does not matters if you know how to write scrapers well. Basically you are doing something on site and inspecting it, so you see what request is send when you are registering or logging in etc. Having information about parameters, request and response content types and headers you can write any scraper without doing any <code>JavaScript</code> work. For some sites it’s easier, for some harder, but whole process looks really similar i.e. do something, observe requests/responses and try to reproduce them. Sometimes you need to read cookies from headers, sometimes token from response body, but scraper is scraper.</p>
<p>Look it’s pretty simple. For doing <code>X</code> scenario <code>JavaScript</code> code needs to send some requests and receive their responses. Developer need to inspect all of them and write <code>Elixir</code> version based on inspected data. Of course instead of static data like tokens you just need a simple function to fetch them from response dynamically.</p>
<p>As said I have experience writing scrapers. I can even write one for you/your company if you want. I just need to know url, full scenario (where to click, what to type etc.) and example data (like test account login data).</p>
<aside class="quote no-group" data-username="JoeZMar" data-post="13" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joezmar/48/11738_2.png" class="avatar"> JoeZMar:</div>
<blockquote>
<p>I would also be willing to pay someone to help me build the rest of an app to further understand Elixir. I really want to start contributing to the community, but I’m just not quite there yet.</p>
</blockquote>
</aside>
<p>Feel free to reach me. <img src="https://forum.elixirforum.com/uploads/default/original/2X/2/20c9c52366de24191270f0b11311379ce60ac82d.gif?v=15" title=":077:" class="emoji emoji-custom" alt=":077:" 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="113664" 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/enum-member-in-a-map-with-multiple-lists/19772/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-113664" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="113664"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="113665" data-post-id="113665">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="idi527" data-post="14" data-topic="19772">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/i/85e7bf/48.png" class="avatar"> idi527:</div>
<blockquote>
<p>It doesn’t work on structs though.</p>
</blockquote>
</aside>
<p>What do you mean?</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Example do
  def sample(data, value, keys \\ [:list_a, :list_b, :list_c]),
    do: data |&gt; Map.take(keys) |&gt; Enum.find(&amp;do_sample(&amp;1, value))

  defp do_sample({_key, list}, value) when is_list(list), do: value in list
end

defmodule ListStruct do
  defstruct [:list_a, :list_b, :list_c]
end

Example.sample(%ListStruct{list_a: [1, 2, 3], list_b: [4, 5, 6], list_c: [7, 8, 9]}, 5)
{:list_b, [4, 5, 6]}
</code></pre>
<p>For me it’s working well.</p>
<aside class="quote no-group" data-username="JoeZMar" data-post="15" data-topic="19772" 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/joezmar/48/11738_2.png" class="avatar"> JoeZMar:</div>
<blockquote>
<p>This is what I just realized. It was the struct that put a kink in it for me. When I start my GS I initialize it with a map with the 5 values with empty lists now and it seems to work.</p>
</blockquote>
</aside>
<p>Sorry, did you mean that you tried to do:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Example.sample(%ListStruct{list_a: nil, list_b: [4, 5, 6], list_c: nil}, 5)
</code></pre>
<p>If so then there are 3 solutions (depends on use case):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># 1. change struct definition:
defstruct [:list_a, :list_b, :list_c]
# to
defstruct [list_a: [], list_b: [], list_c: []]

# 2. use keys enforcing which prevents to create struct with nil values
@enforce_keys [:list_a, :list_b, :list_c]
# in such case this would fail at compile time:
%ListStruct{list_a: nil, list_b: [4, 5, 6], list_c: nil}

# 3. add extra guard:
defmodule Example do
  def sample(data, value, keys \\ [:list_a, :list_b, :list_c]),
    do: data |&gt; Map.take(keys) |&gt; Enum.find(&amp;do_sample(&amp;1, value))

  defp do_sample({_key, nil}, value), do: false
  defp do_sample({_key, list}, value) when is_list(list), do: value in list
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="113665" 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/enum-member-in-a-map-with-multiple-lists/19772/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-113665" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="113665"
                     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>