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