Apex is Awesome Print for Elixir. It pretty-prints Elixir data structures, in color, to make it easy to make sense of their contents. Let's have a look.


We'll kick off a new project just to have somewhere to put the dependency:

mix new apex_playground
cd apex_playground

Now we'll need to add the dependency. Open up mix.exs and add the dependency:

  defp deps do
      {:apex, github: "BjRo/apex"}

Fetch the dependency: mix deps.get

Now let's fire up an iex session to have a look:

Apex.ap 1

So here we're just outputting an integer. Nothing interesting is going on yet. What about a list?

Apex.ap [1,2,3]

Alright, so you can easily see the index of a given value in the data structure. That has some value. What do maps look like?

map = %{foo: "bar", baz: "whee"}
Apex.ap map

So in general, you can see the pattern here - the value to be passed to the Access protocol is laid out beside the data it represents.


It becomes a lot more interesting if you have a deeply nested data structure. Let's make a struct. Open up lib/apex_playground.ex:

defmodule ApexPlayground do
  @derive Access
  defstruct foo: [
    bar: %{
      first: "1",
      second: "2"

Alright, now let's compare IO.inspect with Apex for this nested structure:

play = %ApexPlayground{}
IO.inspect play

So compare that output with Apex's:

Apex.ap play


So Apex is just a really nice tool to aid in debugging or figuring out an unfamiliar data structure. Thought it would be nice to share it. See you soon!