We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
If you are like me and often use pipes in your Elixir code, you might have found that debugging is sometimes a hassle.
I often add IO.inspect
calls in the pipeline to see what the values are.
"Elixir is cool!"
|> String.trim_trailing("!")
|> IO.inspect()
|> String.split()
|> IO.inspect()
|> List.first()
|> IO.inspect()
Running this will output:
"Elixir is cool"
["Elixir", "is", "cool"]
"Elixir"
"Elixir"
There is actually a way better and nicer way to do it by using the dbg/2
function:
"Elixir is cool!"
|> String.trim_trailing("!")
|> String.split()
|> List.first()
|> dbg()
Executhing this will give you:
[iex:10: (file)]
"Elixir is cool!" #=> "Elixir is cool!"
|> String.trim_trailing("!") #=> "Elixir is cool"
|> String.split() #=> ["Elixir", "is", "cool"]
|> List.first() #=> "Elixir"
"Elixir"
As you can see, it will print values at every step of the pipeline.
As always, you can read more about it in the documentation.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.