This problem sounds the same as that solved by free monads mentioned in this thread. These blog posts about monads and error handling in Elixir might help too: 1, 2
@teamon’s example with Flow
is pretty awesome! And thank you for the reading materials