Writing an assert_invalid macro for ExUnit assertions. Implementation at the bottom.

I was working a lot with Ecto Changesets - using them for validation in my HTTP application. The application code (the code in my lib/ folder) was very nice, but I was not happy with the verbosity of the…

# Add to shell profile
export ERL_AFLAGS="-kernel shell_history enabled"

The ERL_AFLAGS variable is for setting a list of options which are added to the beginning of the erl command. In this case, we are adding the shell_history option for saving our shell history between sessions.

Note that “shell” here means…

Using inets and httpd to create a simple HTTP server without adding external dependencies

Recently I needed to add a healthcheck endpoint to an application that was solely responsbile for reading and writing to Kafka. Normally when I am creating an HTTP application I would reach for Cowboy or Phoenix…

Sometimes I come across code where an map (or tuple) is being tested against a pattern to return a boolean result; like this:

An example of pattern matching with a case statement to return a boolean result

That works fine, but can be simplified by using the Kernel.match?/2 function:

An example of pattern matching with Kernel.match?/2 to return a boolean result

Like when using other (more famous)Kernel functions such as ==/2, to_string/1, and send/2, the "Kernel" prefix can be omitted leaving us with a clean one-line statement.

Here is a silly “real-world” example which shows that you can also use guard clauses in your match expression:

An example with a guard clause

Lastly, if you are just testing for one (or maybe two) conditions in a map, keep things simple and stick with a simple Map.get/3 :

An example of keeping things simple and not using pattern matching

Tyler Pachal

Software engineer at PagerDuty, working with Scala and Elixir.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store