Quick debugging in Elixir
I just learned that we can use dbg/2 (https://hexdocs.pm/elixir/1.19.0/debugging.html#dbg-2
) to debug expressions in Elixir. It’s quite useful when used with the pipe operator - unlike IO.inspect, it automatically shows each step in the pipeline.
| |
This prints not only the last result, but also each step of the pipeline:
| |
Output:
| |
Result: "1,4,9"
Other debugging options:
IO.inspect/2- prints a value and returns it (good for pipelines, but shows only one value)IO.puts/1- simple print for stringsdbg/2- shows each pipeline step automatically