logoalt Hacker News

adreganlast Monday at 2:08 PM0 repliesview on HN

There are a couple of patterns for accomplishing this in Elixir.

One is to build multiple function heads that pattern match on the arguments. If it’s an error tuple, pass it along. Build up your pipeline and handle any errors at the end.

Another is to use the `with else`[0] expression for building up a railroad. This has the benefit of not having to teach your functions how to pass along errors. Error handling in the else block can be a little gnarly.

I find it a little more manual than languages that have a `runEffect` or compose operator. In large part that’s due to the :ok, :error tuples being more of a convention than a primitive like Either/Result.

0: https://elixirschool.com/en/lessons/basics/control_structure...