semvec/pypi-packages huggingface dataset:
pyeither 0.1.1
An implementation of Data.Either from Haskell in Python
License: MIT
Keywords: either haskell data.either monad applicative functor

# pyeither

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.
contrapy 2018.1.30
Contracts for Python
License: MIT
Keywords: contracts,contracts-programming

contrapy
========

Contracts for Python 3

.. image:: https://snyk.io/test/github/digitalmensch/contrapy/badge.svg
   :target: https://snyk.io/test/github/digitalmensch/contrapy

.. image:: https://travis-ci.org/digitalmensch/contrapy.svg?branch=master
    :target: https://travis-ci.org/digitalmensch/contrapy

.. image:: https://coveralls.io/repos/github/digitalmensch/contrapy/badge.svg?branch=master
   :target: https://coveralls.io/github/digitalmensch/contrapy?branch=master

.. image:: https://img.shields.io/pypi/pyversions/contrapy.svg
   :target: https://pypi.python.org/pypi/contrapy

.. image:: https://img.shields.io/pypi/l/contrapy.svg
   :target: https://github.com/digitalmensch/contrapy/blob/master/LICENSE

Examples
--------

.. code:: python

    import contrapy
    
    @contrapy.check(lambda a, b, _return: a + b == _return, lambda a, b: a < b)
    def demo(a : 22, b : float) -> float:
        return a + b
    
    >>> demo(22, 33.0)
    55.0
    >>> demo(21, 33.0)
    [...]
    ValueError: a should be 22