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

AstonJ
This blog post hit my timeline earlier, and I’ve also been learning about some fantastic Elixir related tips via @pragdave’s new online c...
New
bluegene
Hi guys, I’ve been on a personal journey to learn Elixir for the past two years. During this journey I’ve been using the spaced repetiti...
New
kuon
I have a page with a large state that is loaded from DB, let’s call that “data”. I have a root live view that load “data” on mount and r...
New
berts-4865
Here is a quick guide to uploading a file from the browser to DO spaces. It is crude, but will hopefully save sometime time and frustrat...
New
lukertty
Install web-mode and mmm-mode first and put this in your config file: (require 'mmm-mode) (require 'web-mode) (setq mmm-global-mode 'may...
New
sergio
Hey there, we’re going to walk through deploying a Phoenix app to a DigitalOcean droplet, manually - no tools no nothing. Just straight u...
New
slouchpie
Warmest greetings, comrades. I recently started using :dns_cluster (GitHub - phoenixframework/dns_cluster: Simple DNS clustering for dis...
New
pinksynth
Whenever tests have to interact with an Ecto.Repo, sometimes it’s necessary to test a few different branches or paths that data can take....
New
caspg
Hi everyone, I recently implemented a real-time search feature in a Phoenix application using LiveView and Tailwind, and I wanted to sha...
New
kevinlang
Hey all, With Phoenix 1.6 just around the corner, I figured I’d make a tutorial on how to add Bulma to a new Phoenix 1.6 project. By lev...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

We're in Beta

About us Mission Statement