/maybe

A simple Rust like Option type for Python 3. Fully type annotated.

Primary LanguagePythonMIT LicenseMIT

Maybe

GitHub Workflow Status (branch) Coverage

A simple Maybe (Option) type for Python 3 inspired by Rust, fully type annotated.

Installation

Latest release:

pip install rustedpy-maybe

Latest GitHub master branch version:

pip install git+https://github.com/rustedpy/maybe

Summary

Experimental. API subject to change.

The idea is that a possible value can be either Some(value) or Nothing(), with a way to differentiate between the two. Some and Nothing are both classes encapsulating a possible value.

Example usage,

from maybe import Nothing, Some

o = Some('yay')
n = Nothing()
assert o.unwrap_or_else(str.upper) == 'yay'
assert n.unwrap_or_else(lambda: 'default') == 'default'

Contributing

These steps should work on any Unix-based system (Linux, macOS, etc) with Python and make installed. On Windows, you will need to refer to the Python documentation (linked below) and reference the Makefile for commands to run from the non-unix shell you're using on Windows.

  1. Setup and activate a virtual environment. See Python docs for more information about virtual environments and setup.
  2. Run make install to install dependencies
  3. Switch to a new git branch and make your changes
  4. Test your changes:
    • make test
    • make lint
    • You can also start a Python REPL and import maybe
  5. Update documentation
    • Edit any relevant docstrings, markdown files
    • Run make docs
  6. Add an entry to the changelog
  7. Git commit all your changes and create a new PR.

License

MIT License