Inspect with Label
IO.inspect
returns the value you pass in as the first argument. This is great when you want to debug the middle state of a series of piped calls.
"ABCDEFG"
|> String.graphemes
|> Enum.each_with_index
|> IO.inspect
|> Enum.map(fn({letter, i}) -> "#{letter}#{i}" end)
|> Enum.join
Here, inspect will write to stdout the values [{"A", 1}, {"B", 2"}...]
.
IO.inspect
also takes a label
option, which decorates the values written to
stdout but does not disrupt the piped calls.
"ABCDEFG"
|> String.graphemes
|> Enum.each_with_index
|> IO.inspect(label: "Letters with index:")
|> Enum.map(fn({letter, i}) -> "#{letter}#{i}" end)
|> Enum.join
Which outputs Letters with index: [{"A", 1}, {"B", 2"}...]
to stdout.