<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="209786" data-post-id="209786">
  <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="lud" data-post="9" data-topic="38819">
<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>You must remove the <code>=</code> here. This is a common mistake I do all the time</p>
</blockquote>
</aside>
<p>Sorry, that was a mistake on my side when creating the reply, the code itself does not suffer from this ailment.<br>
(meaning the error you see is the error I get without the <code>=</code>)</p>
<p>Is the only option here to create a helper module ?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="209786" 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/reusing-compile-time-code/38819/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-209786" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="209786"
                     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="209787" data-post-id="209787">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </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="12" data-topic="38819">
<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>
<p>Is the only option here to create a helper module ?</p>
</blockquote>
</aside>
<p>You can use anonymous functions as well, but a module cannot use it’s own functions at compile time, as those functions are not available before the complete module is compiled. It’s a classic chicken-egg type problem.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="209787" 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/reusing-compile-time-code/38819/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-209787" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="209787"
                     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="209790" data-post-id="209790">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/fl4m3ph03n1x" rel="nofollow">@Fl4m3Ph03n1x</a> Another issue in your code is that you can’t do</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@sports
  @compiled_csv_data
  |&gt; ...
</code></pre>
<p>you need to do</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@sports
  csv_data
  |&gt; ...
</code></pre>
<p>And turns out that in Elixir 1.5 also when declaring the <code>@sports</code> module attribute, to be able to use it in guards you need to do it in two steps. This works:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  sports =
    csv_data
    |&gt; Stream.map(fn {sport, _country, _league} -&gt; sport end)
    |&gt; Enum.filter(fn sport -&gt; sport != "" end)

  @sports sports

  def hard_sport?(sport) when sport in @sports, do: false
</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="209790" 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/reusing-compile-time-code/38819/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-209790" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="209790"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></div>
  </section>
</div>
    <div class="postbit" id="209797" data-post-id="209797">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="michallepicki" data-post="11" data-topic="38819">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/5f9b8f/48.png" class="avatar"> michallepicki:</div>
<blockquote>
<p>I believe you don’t need to <code>require</code> a module to use its functions at compile time</p>
</blockquote>
</aside>
<p>Yes I checked, it is indeed only needed for macros.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="209797" 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/reusing-compile-time-code/38819/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-209797" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="209797"
                     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="209805" data-post-id="209805">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="7" data-topic="38819" 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/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>That‘s not really needed. Macros would only make things more complex, as at no point AST has to be modified.</p>
</blockquote>
</aside>
<p>Sorry, you are right.<br>
It is absolutely not needed, you can get away with it by storing the value at compile time in an attribute and invoke it inside a function.</p>
<p>Something like this based on Michal’s code.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule SportsCsvReader do
  @sports_data         :my_app
    |&gt; :code.priv_dir()
    |&gt; Path.join("awesome_csv.csv")
    |&gt; File.stream!()
    |&gt; CSV.decode!(headers: false, separator: ?;)
    |&gt; Stream.map(&amp;List.to_tuple/1)
    |&gt; Stream.uniq()
    |&gt; Enum.map(fn {sport, country, league} -&gt;
      {String.trim(sport), String.trim(country), String.trim(league)}
    end)

  def sports_data(), do: @sports_data

  def extract_sports(sports_data) do
    sports_data
    |&gt; Enum.map(fn {sport, _country, _league} -&gt; sport end)
    |&gt; Enum.filter(fn sport -&gt; sport != "" end)
  end

  def extract_countries(sports_data) do
    sports_data
    |&gt; Enum.map(fn {_sport, country, _league} -&gt; country end)
  end
end
</code></pre>
<p>My point is that you only need to parse the CSV once, and that is at compile time.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="209805" 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/reusing-compile-time-code/38819/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-209805" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="209805"
                     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>