3 ms·
Rust's Result Type for Python
- pizza 6y agoI'm not super familiar with Rust or MyPy, but I was wondering if you could mention what the distinction is between returning a Result vs e.g. a type hint for returning an exception
- linkdd 6y agoAn exception breaks the "instruction flow". While a Result type can be chained with functions like `map` and `map_or`. This allows you to write your full algorithm/computation, and handle the final result afterwards.
- pizza 6y agoOhh I see. That's pretty cool, reminds me of Maybe monad from Haskell.
- linkdd 6y agoMaybe because Result is a monad, an Either monad to be precise. Monads have been implemented in many languages without the developer even knowing, the best example IMHO are Javascript's Promise which are Continuation Monads.
- asplake 6y agoCan anyone say how this would work with pattern matching? Something for that page to address perhaps