This is an implementation of Rust's Result and Option types in Python. Most methods have been implemented, and the (very good) original documentation

p7g / patina

submited by
Style Pass
2021-05-27 21:00:10

This is an implementation of Rust's Result and Option types in Python. Most methods have been implemented, and the (very good) original documentation has been adapted into docstrings.

The documentation for this package can be read here. All doctests are run and type-checked as part of the CI pipeline as unit tests. The tests are direct ports of those in the Rust documentation.

A similar thing can be done with the Result type (matching on Ok or Err). This can be handy if you want to be more explicit about the fact that a function might fail. If the function returns a Result, we can explicitly type the possible error values.

If this all sounds good, I recommend looking into functional programming, particularly of the ML variety (e.g. Haskell, OCaml, SML) or Rust.

Leave a Comment
Related Posts