Separating the Pure from the Impure
A key functional programming principle is to write as much of your code as possible as pure functions, and move the impure code with side effects to the edges of your system. This is something that comes up often when working with Ecto, as database operations are the very definition of impure.
Fortunately for us, Ecto’s implementation of the Repository Pattern supports this goal. Changesets, queries, and multis are pure data structures that describe impure actions against the database, but these actions don’t take place until we run them through the functions provided by Repo. This creates a clear distinction between code that has side effects and code that doesn’t. If we’re just manipulating the data structures ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access