Implementation of some concepts from category theory
Project description
Pycategories
============
master: |master pipeline| |master coverage|
Pycategories is a Python 3 library that implements ideas from `category theory <https://en.wikipedia.org/wiki/Category_theory>`_, such as monoids, functors, and monads. It provides a Haskell-influenced interface for defining instances of those typeclasses and defines several right out of the box, for example the Maybe monad:
::
>>> from categories import apply
>>> from categories.maybe import Just, Nothing
>>> f = Just(lambda x: x ** 2)
>>> x = Just(17)
>>> apply(f, x)
Just(289)
>>> apply(f, Nothing())
Nothing
Or to define your own instance of a typeclass:
::
>>> from categories import mappend, mempty, monoid
>>> monoid.instance(dict, lambda: {}, lambda a, b: dict(**a, **b))
>>> mappend({'foo': 'bar'}, {'rhu': 'barb'})
{'foo': 'bar', 'rhu': 'barb'}
Installation
------------
::
pip install pycategories
To clone the repo and install dependencies for development: ::
git clone https://gitlab.com/danielhones/pycategories
cd pycategories
pip install -e .[dev]
Support and Contributing
------------------------
* `Issue Tracker <https://gitlab.com/danielhones/pycategories/issues>`_
* `Source code <https://gitlab.com/danielhones/pycategories>`_
License
-------
Pycategories is licensed under the `MIT License <https://gitlab.com/danielhones/pycategories/blob/master/LICENSE>`_
Documentation
-------------
Documentation is available at `pycategories.readthedocs.io <http://pycategories.readthedocs.io/>`_
============
master: |master pipeline| |master coverage|
Pycategories is a Python 3 library that implements ideas from `category theory <https://en.wikipedia.org/wiki/Category_theory>`_, such as monoids, functors, and monads. It provides a Haskell-influenced interface for defining instances of those typeclasses and defines several right out of the box, for example the Maybe monad:
::
>>> from categories import apply
>>> from categories.maybe import Just, Nothing
>>> f = Just(lambda x: x ** 2)
>>> x = Just(17)
>>> apply(f, x)
Just(289)
>>> apply(f, Nothing())
Nothing
Or to define your own instance of a typeclass:
::
>>> from categories import mappend, mempty, monoid
>>> monoid.instance(dict, lambda: {}, lambda a, b: dict(**a, **b))
>>> mappend({'foo': 'bar'}, {'rhu': 'barb'})
{'foo': 'bar', 'rhu': 'barb'}
Installation
------------
::
pip install pycategories
To clone the repo and install dependencies for development: ::
git clone https://gitlab.com/danielhones/pycategories
cd pycategories
pip install -e .[dev]
Support and Contributing
------------------------
* `Issue Tracker <https://gitlab.com/danielhones/pycategories/issues>`_
* `Source code <https://gitlab.com/danielhones/pycategories>`_
License
-------
Pycategories is licensed under the `MIT License <https://gitlab.com/danielhones/pycategories/blob/master/LICENSE>`_
Documentation
-------------
Documentation is available at `pycategories.readthedocs.io <http://pycategories.readthedocs.io/>`_
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
pycategories-1.0.0.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for pycategories-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b75240c08e33c26d13b923d51594f578a4d3ceec47f2af62618ee4b803b9013 |
|
MD5 | 208f77c0af40d3cb18716df211c019ce |
|
BLAKE2b-256 | 09cc91fe58779467f67ecc26b8a96da9fc95779557a077ea947c7fb4efc675fb |