smpallen99

smpallen99

Debugging a pipeline with IO.inspect/2

Did you know that IO.inspect/2 returns the the first argument and accepts a label option as a second argument. This makes it a perfect tool to logging intermediate results in a pipeline, as well as intermediate results in a function. Take the following pipeline, for example:

def get_gifts(santa, wishlist, snack) do
  santa
  |> receives_wishlist(wishlist)
  |> leaves_presents
  |> eats(snack)
  |> wakeup_to
end

Now lets say that you don’t get your gifts. Try the following:

def get_gifts(santa, wishlist, snack) do
  santa
  |> receives_wishlist(wishlist)
  |> IO.inspect(label: "after wishlist received")
  |> leaves_presents()
  |> IO.inspect(label: "after presents")
  |> eats(snack)
  |> wakeup_to()
  |> IO.inspect(label: "result")
end

Most Liked

voger

voger

I think there is a bug in your code. You should pattern match for :naughty or :nice or something. That’s why the gift doesn’t get delivered.

Sorry for the offtopic. I couldn’t resist. :smiley:

smpallen99

smpallen99

I would love to see it implemented for logger too. I’ve been burned a couple times with at :ok return value.

NobbZ

NobbZ

Indeed a very nice feature! And on the issue tracker there is even a discussion about making this possible for Logger calls as well…

Where Next?

Popular in Guides/Tuts Top

fuelen
Hi all! Just want to share a small code snippet which allows writing CASE expressions using macro which is similar to cond. Here is an ...
New
jswny
Hello everyone, I recently redesigned my entire deployment process for Phoenix apps based on Docker. I really like the strategy that I ca...
New
alejandroErik
POST IN CONSTRUCTION Process for compile erlang otp 20 with odbc-unix for Oracle connections on Solaris 11.3 for 64 bits: Introductio...
New
dkuhlman
For those of you who might be interested in using ZeroMQ in Elixir, I converted the Erlang examples in the ZeroMQ “zguide” to Elixir. I ...
New
emilsoman
Hello, While answering a StackOverflow question on how to debug an elixir node running remotely, I thought it may be helpful to write a ...
New
yeshan333
vfox (version-fox) is a popular general version management tool write in Go, and the plug-in mechanism uses Lua to achieve extensibility....
New
mudasobwa
The post covering how to generate nifty types to use in @spec in compile time with macros.
New
smpallen99
Some advice for Elixir programmers. I was reviewing someone’s Elixir Code yesterday and found a deadlock condition bug in a GenServer im...
New
mhanberg
Hi! I recently finished adding authentication to my Phoenix API, so I wanted to share what I learned. I haven’t created authentication f...
New
nelsonic
When we were figuring out how to use Phoenix LiveView we got stuck a few times. So in order to save other people time, we created a comp...
New

Other popular topics Top

New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement