by DougBTX · 6y ago · 0 comments
The original Python code using exceptions was:
sink = transform3(transform2(transform1(source)))
Making that use error return values looks quite verbose in Go, but Rust has syntax specifically for that case, making it quite manageable: sink = transform3(transform2(transform1(source)?)?)?Rust would have solved three of his complaints with Go: Sum types, iterators, and generics.
Borrow checking can get especially tricky with graph algorithms though, so perhaps that would have been a new issue.
i.e transform1 returns (result, error) and transform2 accepts (result, error) and short-circuits if err is not nil.
It allows the expressive and succinct description of a transformation list but with a bunch of messiness hidden.
fn(fn(fn()?)?)? is a bit gnarly but better than duplicate code like that, imo.