The pattern you describe does see some usage in some existing Elixir libraries. For instance, Ecto.Multi.
If the amount of successes/errors is large enough, such a pattern might make sense.
However, it might be better to split your with into multiple subfunctions that work at different levels of detail. This will make them shorter and the error-handling part of them more readable.
For instance, all the errors returned by function_a could have a similar shape. Then you’ll only need a single line in your else-block to forward all of these.
And even better would be to have the errors directly match what you want as output, rather than having to do a lot of wrapping/mapping of them.
There are also some libraries which remove some of the repetitive boilerplate of with-statements. (my contender: ‘Solution’)






















