4 ms·
I'm six months into my Python journey. We aren't building a library, so everything runs on 3.11. Having spent most of my career in statically typed and sometime
by ed_blackburn 3y ago
I'm six months into my Python journey. We aren't building a library, so everything runs on 3.11. Having spent most of my career in statically typed and sometimes functional languages, I've found the result package approach and pattern-matching suggestion work well. There's been a suggestion it's not very Pythonic, but I'm willing to continue using a result monad because the trade-off is one-sided; it comfortably pays for itself.
- all2 3y agoWhat is a result monad?
- avgcorrection 3y agoIt is linguistically related to the (plus, int) monoid; the fact that it conforms to some algebraic/categorical interface is irrelevant in most contexts and just a distraction. (A “Result” is Rust-speak for a sum type which is either A or B, where (say) B is conventionally an error)
- ed_blackburn 3y agoThe result package in the article: https://github.com/rustedpy/result https://github.com/rustedpy/result There's a pretty decent explanation in the readme. If you're more interested in Monads, I am not sure I'd cover that in a HN comment very well, but I would encourage you to take a look.
- itishappy 3y agoIt just lets you combine results in an intuitive way: Ok(2) + Ok(3) = Ok(5) Ok(2) + Err() = Err() Err() + Ok(3) = Err()