Name | python-monads JSON |
Version |
0.0.8
JSON |
| download |
home_page | None |
Summary | Either and Maybe monads for Python |
upload_time | 2025-01-09 08:31:52 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | The MIT License (MIT) Copyright (c) 2025 Pol Dellaiera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
monad
functional-programmtion
complexity
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![GitHub Workflow Status][github workflow status]][github actions link]
[![Donate!][donate github]][github sponsors link]
# Python-Monads
`python-monads` is a Python library that provides implementations for `Either`
and `Maybe` monads. These functional programming constructs help simplify error
handling, chaining computations, and dealing with optional values in a clean and
expressive way.
## Features
- **`Either` Monad**: Represent computations that can return a result (`Right`)
or an error (`Left`).
- **`Maybe` Monad**: Encapsulate optional values, eliminating the need for
`None` checks.
- **Type-safe and Pythonic**: Leverages Python's type hints and idiomatic
programming style.
- **Extensive Test Suite**: Ensure reliability with a high test coverage.
## Installation
### Using UV
```bash
uv add python-monads
```
## Quick Start
### Using `Either`
```python
from python_monads.either import Either
# Example with Right
result = Either.from_right("Success")
print(result) # Output: Right(Success)
# Example with Left
error = Either.from_left("Error")
print(error) # Output: Left(Error)
def process_value(value):
return Either.from_right(value.upper())
# Chaining computations
chained_result = result.bind(process_value)
print(chained_result) # Output: Right(SUCCESS)
```
### Using `Maybe`
```python
from python_monads.maybe import Maybe
# Example with value
value = Maybe.just(42)
print(value) # Output: 42
# Example with None
nothing = Maybe.nothing()
print(nothing) # Output: None
# Transforming values
result = value.map(lambda x: x * 2)
print(result) # Output: 84
```
## Development Setup
This project uses **Nix** for reproducible development environments.
### Prerequisites
- [Nix](https://nixos.org/)
### Setup
1. Clone the repository:
```bash
git clone https://github.com/drupol/python-monads.git
cd python-monads
```
2. Create a virtual environment and install dependencies:
```bash
nix develop
```
## Testing
Run the tests using `pytest`:
```bash
pytest
```
### Code Style
We use [Ruff](https://github.com/astral-sh/ruff) for linting and formatting. Run
the following command to ensure your code adheres to the style guide:
```bash
ruff check .
ruff format .
```
## Contributing
Feel free to contribute by sending pull requests. We are a usually very
responsive team and we will help you going through your pull request from the
beginning to the end, read more about it in the
[documentation][contributing doc page].
For some reasons, if you can't contribute to the code and willing to help,
sponsoring is a good, sound and safe way to show us some gratitude for the hours
we invested in this package.
Sponsor me on [Github][github sponsors link] and/or any of [the
contributors][the contributors].
[github actions link]: https://github.com/drupol/python-monads/actions
[github sponsors link]: https://github.com/sponsors/drupol
[github workflow status]:
https://img.shields.io/github/actions/workflow/status/drupol/python-monads/tests.yml?branch=main&style=flat-square
[donate github]:
https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square
[the contributors]: https://github.com/loophp/collection/graphs/contributors
Raw data
{
"_id": null,
"home_page": null,
"name": "python-monads",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "monad, functional-programmtion, complexity",
"author": null,
"author_email": "Pol Dellaiera <pol.dellaiera@protonmail.com>",
"download_url": "https://files.pythonhosted.org/packages/93/ee/a8674cc593de7df21f99f4785f0567f0222291595890e62259fff31aac3f/python_monads-0.0.8.tar.gz",
"platform": null,
"description": "[![GitHub Workflow Status][github workflow status]][github actions link]\n[![Donate!][donate github]][github sponsors link]\n\n# Python-Monads\n\n`python-monads` is a Python library that provides implementations for `Either`\nand `Maybe` monads. These functional programming constructs help simplify error\nhandling, chaining computations, and dealing with optional values in a clean and\nexpressive way.\n\n## Features\n\n- **`Either` Monad**: Represent computations that can return a result (`Right`)\n or an error (`Left`).\n- **`Maybe` Monad**: Encapsulate optional values, eliminating the need for\n `None` checks.\n- **Type-safe and Pythonic**: Leverages Python's type hints and idiomatic\n programming style.\n- **Extensive Test Suite**: Ensure reliability with a high test coverage.\n\n## Installation\n\n### Using UV\n\n```bash\nuv add python-monads\n```\n\n## Quick Start\n\n### Using `Either`\n\n```python\nfrom python_monads.either import Either\n\n# Example with Right\nresult = Either.from_right(\"Success\")\nprint(result) # Output: Right(Success)\n\n# Example with Left\nerror = Either.from_left(\"Error\")\nprint(error) # Output: Left(Error)\n\ndef process_value(value):\n return Either.from_right(value.upper())\n\n# Chaining computations\nchained_result = result.bind(process_value)\nprint(chained_result) # Output: Right(SUCCESS)\n```\n\n### Using `Maybe`\n\n```python\nfrom python_monads.maybe import Maybe\n\n# Example with value\nvalue = Maybe.just(42)\nprint(value) # Output: 42\n\n# Example with None\nnothing = Maybe.nothing()\nprint(nothing) # Output: None\n\n# Transforming values\nresult = value.map(lambda x: x * 2)\nprint(result) # Output: 84\n```\n\n## Development Setup\n\nThis project uses **Nix** for reproducible development environments.\n\n### Prerequisites\n\n- [Nix](https://nixos.org/)\n\n### Setup\n\n1. Clone the repository:\n\n ```bash\n git clone https://github.com/drupol/python-monads.git\n cd python-monads\n ```\n\n2. Create a virtual environment and install dependencies:\n\n ```bash\n nix develop\n ```\n\n## Testing\n\nRun the tests using `pytest`:\n\n```bash\npytest\n```\n\n### Code Style\n\nWe use [Ruff](https://github.com/astral-sh/ruff) for linting and formatting. Run\nthe following command to ensure your code adheres to the style guide:\n\n```bash\nruff check .\nruff format .\n```\n\n## Contributing\n\nFeel free to contribute by sending pull requests. We are a usually very\nresponsive team and we will help you going through your pull request from the\nbeginning to the end, read more about it in the\n[documentation][contributing doc page].\n\nFor some reasons, if you can't contribute to the code and willing to help,\nsponsoring is a good, sound and safe way to show us some gratitude for the hours\nwe invested in this package.\n\nSponsor me on [Github][github sponsors link] and/or any of [the\ncontributors][the contributors].\n\n[github actions link]: https://github.com/drupol/python-monads/actions\n[github sponsors link]: https://github.com/sponsors/drupol\n[github workflow status]:\n https://img.shields.io/github/actions/workflow/status/drupol/python-monads/tests.yml?branch=main&style=flat-square\n[donate github]:\n https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square\n[the contributors]: https://github.com/loophp/collection/graphs/contributors\n",
"bugtrack_url": null,
"license": "The MIT License (MIT) Copyright (c) 2025 Pol Dellaiera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Either and Maybe monads for Python",
"version": "0.0.8",
"project_urls": {
"Homepage": "https://github.com/drupol/python-monads",
"Issues": "https://github.com/drupol/python-monads/issues",
"Repository": "https://github.com/drupol/python-monads.git"
},
"split_keywords": [
"monad",
" functional-programmtion",
" complexity"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f9c67a8d21e63dbd537fd545f1dc91224ba12d15a98fd467e52a6c02b53641ba",
"md5": "a3557ba16a467e547890ada585e2fa6f",
"sha256": "f685d3ee1210ea282c5b655f796503e28c70b19edba166019feaa7492996ab69"
},
"downloads": -1,
"filename": "python_monads-0.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a3557ba16a467e547890ada585e2fa6f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 7417,
"upload_time": "2025-01-09T08:31:51",
"upload_time_iso_8601": "2025-01-09T08:31:51.377395Z",
"url": "https://files.pythonhosted.org/packages/f9/c6/7a8d21e63dbd537fd545f1dc91224ba12d15a98fd467e52a6c02b53641ba/python_monads-0.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "93eea8674cc593de7df21f99f4785f0567f0222291595890e62259fff31aac3f",
"md5": "030096d3dc428980662a585053753307",
"sha256": "3b72d7c6fe7b7ba4844c81338fa22b4f029e26bab7b3ef383e929e6a9ab4493e"
},
"downloads": -1,
"filename": "python_monads-0.0.8.tar.gz",
"has_sig": false,
"md5_digest": "030096d3dc428980662a585053753307",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 7088,
"upload_time": "2025-01-09T08:31:52",
"upload_time_iso_8601": "2025-01-09T08:31:52.784950Z",
"url": "https://files.pythonhosted.org/packages/93/ee/a8674cc593de7df21f99f4785f0567f0222291595890e62259fff31aac3f/python_monads-0.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-09 08:31:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "drupol",
"github_project": "python-monads",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "python-monads"
}