Add Helper Functions
Learn how to add IEx helper functions.
Learning how to add imports and aliases is a good start, but remember that .iex.exs
is just a regular Elixir file, so we can define modules and functions as well. Consider the example we were just discussing, which was making a change to a record in the database. Normally, this process requires a few steps, but we can create a helper function that will handle most of the boilerplate.
Where to put IEx helper functions?
We usually like to put our IEx helper functions into a single module and to give the module a very short name so it’s easy to type. We tend to use H
or EH
for “helper” or “Ecto helper,” respectively. Normally, these would be poor choices for module names, as they’re not descriptive enough for someone reading our code to understand what they do. We’re creating a module that will only be used within IEx, though, so we can optimize for easy typing over readability.
Add and try out a helper function
Now, let’s add our new helper function for making changes.
Get hands-on with 1400+ tech skills courses.