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
Trending in Guides/Tuts
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First 3 of 3 Posts!
NobbZ
Indeed a very nice feature! And on the issue tracker there is even a discussion about making this possible for
Loggercalls as well…voger
I think there is a bug in your code. You should pattern match for
:naughtyor:niceor something. That’s why the gift doesn’t get delivered.Sorry for the offtopic. I couldn’t resist.
smpallen99
I would love to see it implemented for logger too. I’ve been burned a couple times with at :ok return value.