Hacker News new | ask | show | jobs
by dnautics 2849 days ago
the pipes are worth it for the IO.inspect pattern alone.

For those who are not familiar, in Elixir you can write

    result = value
    |> f1()
    |> f2()
and that is equvalent to

    result = f2(f1(value))
IO.inspect is a function that will fork a copy of its passed parameter to stdout, pretty-printed, and pass its parameter as the sole result.

so if you wanted to check on on the values you can do this:

    result = value
    |> IO.inspect(label: "value")
    |> f1()
    |> IO.inspect(label: "result-of-f1")
    |> f2()
    |> IO.inspect(label: "result-of-f2")
This makes "println debugging" super, super, easy, because post facto cleanup doesn't require rebalancing your parentheses.