A functional Python library that exposes `Data.Either` from Haskell.
```haskell
data Either e a = Left e | Right a
```
## Example Usage
```python
import os
import json
import either
def main():
path = "~/myfile.json"
# Lift a normal value into Either
e_path = either.pure(path)
# Ensure the path is valid, returning Right(path) if it is or Left("not a file") if it isn't
e_valid = e_path.bind(either.predicate(os.path.isfile, "not a file"))
# Load a file as json, returning Right(contents) if it works, or Left(exc) if it doesn't
e_data = e_valid.bind(lambda p: either.attempt(json.load, p))
# It's annoying to assign intermediate values to variables, so you can chain expressions
# Equivalent to above:
e_data2 = (either.pure(path)
.bind(either.predicate(os.path.isfile, "not a file"))
.bind(lambda p: either.attempt(json.load, p)))
# Python lacks do-notation, so there's not a nice equivalent syntax
# Build pipelines of actions using monadic composition
ensure_path = either.predicate(os.path.isfile, "not a file")
load_file = lambda p: either.attempt(json.load, p)
process = either.kleisli(ensure_path, load_file)
# Equivalent to above:
e_data3 = either.pure(path).bind(process)
```
## Getting pyeither
```
pip install pyeither
```
## Motivation
I've created an IPython Notebook that describes the motivation for this project
as an interactive tutorial building an analogous system from scratch. If you're
interested in learning more about the **why** of this project, please check it
out!
[**Motivation Notebook**](https://github.com/SegFaultAX/pyeither/blob/master/pyeither_demo.ipynb)
## Special Thanks
This library depends on the absolutely wonderful
[`attrs`](http://www.attrs.org/en/stable/) library, without which there would
have been far more ugly boilerplate.
## License
Copyright 2018 Michael-Keith Bernard
See LICENSE.txt for the full license.
Metadata
Release files for pyeither 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyeither-0.1.1.tar.gz | 7.6 kB | Without provenance | Details for pyeither-0.1.1.tar.gz |
Release files / pyeither-0.1.1.tar.gz
| Download URL | pyeither-0.1.1.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94b81cfee95babe28e00ece54f376969d48e0721bc9ba109e90a5aa1e1393cbc
|
|
BLAKE2b-256 checksum How to use checksums |
03ebf3aa3a384c1e9548e77c24ecc81944b1076ad9fdfc343bc9237e45be2708
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pyeither 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.