std_result - A way to standardize function returns

ok_tuple, wrap_in_ok ok_wrap, wrap_in_ok_tuple, to_ok_tuple.

Solution 1 is evil, bad, bad, naughty, ugly, eww, yucky.
Solution 3 is to return exception structs, as discussed in the thread you linked, in keathley’s blog post that @soadpopcan lined and this one. Using this method, you can either ignore the error, raise it or use it.

Your example is still contrived because you either don’t care which error it is or all you’re doing with the error is IO.puts. All of those User and Country functions must be in your codebase(?), so you could easily write functions that return ok/error tuples if that is what you need.

To me, it feels easier to rewrite a function in a legible way than to introduce a library that does things in an idiomatic-Rust/non-idomatic-Elixir way. You can’t call your library idiomatic Elixir code if you just wrote it and nobody is using it yet.

As @sodapopcan touched on, pipes are often data transformations, and putting a bunch of conditionals in a pipe makes the control flow difficult to see at a glance.

2 Likes