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

tfwright
I thought I’d share a small project I’m working on to gain some familiarty with LiveView in a Phoenix app. Github Repo Deployment It’s...
New
dennisreimann
I wrote a guide for implementing Passwordless Authentication a.k.a. “Magic Login Links”: https://dennisreimann.de/articles/phoenix-passw...
New
stryrckt
I’m excited about the new LiveComponents feature in LiveView, but I haven’t seen much written on it, so I decided to write a couple of ar...
New
hauleth
Some time ago someone suggested me to write article about how I have configured my Vim to work with Elixir, now there it is: https://med...
New
Eiji
Hey, today I give amnesia library a try and found a few problems. I would like describe how to setup it properly and solve problems which...
New
jshprentz
Geoffrey Lessel’s 2019 book, Phoenix in Action, was written for Phoenix 1.4. I found that the book’s code examples did not match the cur...
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
dmitriid
This is not a question, but a post for anyone who may need it in the future. Sometimes some browsers may mangle the filename if it’s non-...
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
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

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement