IO.inspect Label
When doing puts-driven-development in Elixir, IO.inspect/1
and IO.inspect/2
are very useful. These functions return their items unchanged, allowing us to spy on a value in our Elixir code.
I'm a fan of the :label
option, which decorates our output with a label, making it easier to understand.
def channel_name_split(channel) do
channel.name
|> IO.inspect(label: "channel name before")
|> String.split("")
|> IO.inspect(label: "channel name after")
end
And here's the output in our server log:
channel name before: "workflow"
channel name after: ["", "w", "o", "r", "k", "f", "l", "o", "w", ""]
Check out h IO.inspect
in IEX for more info.