|
| 1 | +# Maybe |
| 2 | + |
| 3 | +[](https://github.com/rustedpy/maybe/actions/workflows/ci.yml?query=branch%3Amaster) |
| 4 | +[](https://codecov.io/gh/rustedpy/maybe) |
| 5 | + |
| 6 | +A simple Maybe (Option) type for Python 3 [inspired by Rust]( |
| 7 | +https://doc.rust-lang.org/std/option/), fully type annotated. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Latest release: |
| 12 | + |
| 13 | +```sh |
| 14 | +$ pip install rustedpy-maybe |
| 15 | +``` |
| 16 | + |
| 17 | + |
| 18 | +Latest GitHub `master` branch version: |
| 19 | + |
| 20 | +```sh |
| 21 | +$ pip install git+https://github.com/rustedpy/maybe |
| 22 | +``` |
| 23 | + |
| 24 | +## Summary |
| 25 | + |
| 26 | +**Experimental. API subject to change.** |
| 27 | + |
| 28 | +The idea is that a possible value can be either `Some(value)` or `Nothing()`, |
| 29 | +with a way to differentiate between the two. `Some` and `Nothing` are both |
| 30 | +classes encapsulating a possible value. |
| 31 | + |
| 32 | +Example usage, |
| 33 | + |
| 34 | +```python |
| 35 | +from maybe import Nothing, Some |
| 36 | + |
| 37 | +o = Some('yay') |
| 38 | +n = Nothing() |
| 39 | +assert o.unwrap_or_else(str.upper) == 'yay' |
| 40 | +assert n.unwrap_or_else(lambda: 'default') == 'default' |
| 41 | +``` |
| 42 | + |
| 43 | +## Contributing |
| 44 | + |
| 45 | +These steps should work on any Unix-based system (Linux, macOS, etc) with Python |
| 46 | +and `make` installed. On Windows, you will need to refer to the Python |
| 47 | +documentation (linked below) and reference the `Makefile` for commands to run |
| 48 | +from the non-unix shell you're using on Windows. |
| 49 | + |
| 50 | +1. Setup and activate a virtual environment. See [Python docs][pydocs-venv] for more |
| 51 | + information about virtual environments and setup. |
| 52 | +2. Run `make install` to install dependencies |
| 53 | +3. Switch to a new git branch and make your changes |
| 54 | +4. Test your changes: |
| 55 | + - `make test` |
| 56 | + - `make lint` |
| 57 | + - You can also start a Python REPL and import `maybe` |
| 58 | +5. Update documentation |
| 59 | + - Edit any relevant docstrings, markdown files |
| 60 | + - Run `make docs` |
| 61 | +6. Add an entry to the [changelog](./CHANGELOG.md) |
| 62 | +5. Git commit all your changes and create a new PR. |
| 63 | + |
| 64 | +[pydocs-venv]: https://docs.python.org/3/library/venv.html |
| 65 | + |
| 66 | +## License |
| 67 | + |
| 68 | +MIT License |
0 commit comments