3 ms·
If you want to chain 3 calls and short circuit on the first error, don't use Go. I like explicit code without magic that I can't see. for a <- a() b
by KingOfCoders 2y ago
If you want to chain 3 calls and short circuit on the first error, don't use Go. I like explicit code without magic that I can't see.
for a <- a()
b <- b() {
...
}
I don't know what is happening there. Is it summing up errors? Is if short circuiting? Does it have error handling? Is it async? Is it a monad stack with transformers? That code could mean anything. Good luck coming back to that code after six months. I think the Sum type solution focuses on the happy path, the Go solution assumes you need to focus on the things that go wrong.
Additionally you have that nasty dependency of the Result type of a() to b() to make it work. And I've spent hours creating the right Transformer stack to compose more than two monad types like Result, Future and IO.