...

/

Separate the Pure Code from the Impure Code

Separate the Pure Code from the Impure Code

Learn how to separate the pure code from the impure code.

Key principle of functional programming

A key functional programming principle is to write as much of the code as possible as pure functions and move the impure code with side effects to the edges of the system. This comes up often when working with Ecto, as database operations are the very definition of impure.

Repository pattern

Fortunately for us, Ecto’s Repository Pattern implementation supports this goal. Changesets, queries, and multis are pure data structures that describe impure actions against the database, but these actions don’t occur until we run them through the functions provided by Repo ...