Best practice: Avoid duplicating module attributes
masterWhen using the module attribute generated by :as (e.g., @posts), avoid injecting it directly into multiple functions. Each time you reference the attribute in a function body, it may cause a complete copy of the collection to be made.
Incorrect:
def all_posts, do: @posts
def recent_posts, do: Enum.take(@posts, 3)Correct: Define a single function to access the attribute and have other functions call that function.
def all_posts, do: @posts
def recent_posts, do: Enum.take(all_posts(), 3)