I try to use with
as much as I can and for all other stuff I like sage
, https://hex.pm/packages/sage
See the post: https://medium.com/nebo-15/introducing-sage-a-sagas-pattern-implementation-in-elixir-3ad499f236f6
I try to use with
as much as I can and for all other stuff I like sage
, https://hex.pm/packages/sage
See the post: https://medium.com/nebo-15/introducing-sage-a-sagas-pattern-implementation-in-elixir-3ad499f236f6
The with
examples given above all seem like they could be cleaned up with macro to handle threading the success result back around into the next function. Similar to pipe, actually. Would that be possible? Or are real-life uses not so neat and tidy?
If you’re just simply threading a success result through to the next function then you would want to look at the previously mentioned https://github.com/CrowdHailer/OK
(or https://github.com/expede/exceptional if you want something more monady)
happy
and throw
are not mentioned during this discussion, I wonder why that is.
It seems to me that expressing a |> clear |> happy(path)
is the most important benefit of using pipes.
Functions can be designed to throw
when they are not happy.
Data that is thrown can be formatted in such a way that it is easy to catch
just like you would catch an unhappy with
outcome using else
.
Combining |>
, throw
and catch
can help express both the happy path and every unhappy scenario very clearly.
Of course I’m not saying that a public api should throw stuff.