Hacker News new | ask | show | jobs
by all2 952 days ago
What is a result monad?
3 comments

It just lets you combine results in an intuitive way:

    Ok(2) + Ok(3) = Ok(5)

    Ok(2) + Err() = Err()

    Err() + Ok(3) = Err()
The result package in the article: 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.

It 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)