Solution: library to do pattern-matching with general ok/error types in case/with statements -- v1.0.1

No, Solution does not overload any operators.

The choice was made to keep in line with Elixir’s own decision to use with statements as a more explicit alternative to ‘short-circuiting pipes’. The only change that Solution does w.r.t. the built-in versions of Elixir’s with (and case) is that the caller of a function does no longer have to care how many elements the returned tuple has, but only if it is an ok or an error.

If you really want short-circuiting pipe operators, I’d suggest either you look at this post earlier in this topic for a comparison of the various libraries that have making ok/error tuples nicer to work with as goal. Many of them do either overload the pipe operator, introduce a new operator, or introduce a ‘monadic do’-style syntax.

EDIT: That said, it also is possible to define your own custom pipe-like operator on top of the is_ok/is_error guards that Solution provides (which, as mentioned, let you match any of:ok, {:ok, val}, {:ok, val, meta}, {:ok, val, meta, other}, etc and similarly for is_error). Let me conjure up a code snippet for you…

1 Like