This library brings common monads such `Maybe` and `Either` to your Python projects.
Project description
Pyella
This library brings common monads such as Maybe
and Either
to your Python projects.
Requirements
- Python 3.7+
Installation
pip3 install pyella
Usage
Maybe
The snippet below demonstrates some of the oprations that are available for Maybe
.
from pyella.maybe import Maybe
j0 = Maybe.of(1)
print (j0)
# Output: Just(1)
print (j0.from_maybe(-1))
# Output: 1
j1 = j0.fmap(lambda x:x*2)
print(j0)
print(j1)
# Output:
#
# Just(1)
# Just(2)
Either
And these are some things you can do with Either
.
from pyella.either import Either, left, lefts, right, rights
e0: Either[str, int] = left("invalid value")
print(e0)
# Output: Left(invalid value)
print (e0.if_left(-1))
print (e0.if_right("the value was valid"))
# Output:
#
# -1
# 'invalid value'
e1: Either[str, int] = right(1)
print (e1)
# Output: Right(1)
e2 = e1.fmap(lambda x:x*2)
print(e1)
print(e2)
# Output:
#
# Right(1)
# Right(2)
valid_values = rights([e0, e1, e2])
print (valid_values)
# Output: [1, 2]
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
Code of Conduct
Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
License
MPL-2.0
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
pyella-1.1.1.tar.gz
(9.6 kB
view hashes)
Built Distribution
pyella-1.1.1-py3-none-any.whl
(15.3 kB
view hashes)