Monads for python made simple and safe.
Project description
dry-monads
Monads for python
made simple and safe.
Features
- Provides primitives to write declarative business logic
- Fully typed with annotations and checked with
mypy
, allowing you to write type-safe code as well - No operator overloading or other unpythonic stuff that makes your eyes bleed
Installation
pip install dry-monads
What's inside?
We have several the most iconic monads inside:
- Result, Failure, and Success (also known as
Either
,Left
, andRight
) - Maybe, Some, and Nothing
We also care about code readability and developer experience, so we have included some useful features to make your life easier:
Example
from returns.do_notation import do_notation
from returns.either import Result, Success, Failure
class CreateAccountAndUser(object):
"""Creates new Account-User pair."""
@do_notation
def __call__(self, username: str, email: str) -> Result['User', str]:
"""Can return a Success(user) or Failure(str_reason)."""
user_schema = self._validate_user(username, email).unwrap()
account = self._create_account(user_schema).unwrap()
return self._create_user(account)
# Protected methods
# ...
We are covering what's going on in this example in the docs.
Inspirations
This module is heavily based on:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
returns-0.2.0.tar.gz
(8.4 kB
view details)
Built Distribution
returns-0.2.0-py3-none-any.whl
(22.8 kB
view details)
File details
Details for the file returns-0.2.0.tar.gz
.
File metadata
- Download URL: returns-0.2.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.11 CPython/3.6.6 Darwin/18.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd7c37a745255d034fcb03e969a0927a820ae456c2c76c6e1968e6875ab25fac |
|
MD5 | 4898ebc78056842ec5bc0486664e7693 |
|
BLAKE2b-256 | 109090aa7f935f96447bdbde413478cf969cb3448bcc28a1780c0edd0e4398dc |
File details
Details for the file returns-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: returns-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.11 CPython/3.6.6 Darwin/18.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78d3fbfad8bf2e1934f1ee84f6bed3fba92ffaae156d441d3b118622379b8d0a |
|
MD5 | ec8c719dd853a3f62a76f66043e8c288 |
|
BLAKE2b-256 | f030e473806d819960ea7b0cbaa240be835f5f7f09ea52b29716f2b6aa0ae788 |