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 dry_monads.do_notation import do_notation
from dry_monads.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
dry-monads-0.2.0.tar.gz
(8.3 kB
view hashes)
Built Distribution
dry_monads-0.2.0-py3-none-any.whl
(22.9 kB
view hashes)
Close
Hashes for dry_monads-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64828e97d308052e95bd1233e7bf5b7a1f76c10e18a0d565b6f763a8c17f8cfe |
|
MD5 | 829d963dfaeaaf3b8e93ea860f21158f |
|
BLAKE2b-256 | b60e5ad9a35e1c1b500637230416d13d69f723777973192e6e94102769abed47 |