Make your functions return something meaningful and safe!
Project description
returns
Make your functions return something meaningful 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 - Pythonic and pleasant to write and to read (!)
Installation
pip install returns
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.3.1.tar.gz
(9.3 kB
view details)
Built Distribution
returns-0.3.1-py3-none-any.whl
(29.9 kB
view details)
File details
Details for the file returns-0.3.1.tar.gz
.
File metadata
- Download URL: returns-0.3.1.tar.gz
- Upload date:
- Size: 9.3 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 | d9dbd06e18bd3291ecf68768ef2d055ba7a48327ab199214988360c48d89a1bb |
|
MD5 | 950b3c56a6bf0e16b496f3614c3ac873 |
|
BLAKE2b-256 | 1893bfad45bce4385e017e35253f2c9fbedfd312720b03c1af5124458c6434d6 |
File details
Details for the file returns-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: returns-0.3.1-py3-none-any.whl
- Upload date:
- Size: 29.9 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 | 3c34473e7fc62294551ac72f19461610e9989c5315e2688a67d819e2c8338bc0 |
|
MD5 | 74c377c34a2bdf15f023687f4d5f0db1 |
|
BLAKE2b-256 | 16d3c25201f48b415da7a8205d9723f3a6869b9b94aa5a2f2c17aa0d69eedcf0 |