Implementation of some concepts from category theory
Project description
Pycategories is a Python 3 library that implements ideas from 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
License
Pycategories is licensed under the MIT License
Documentation
Documentation is available at 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.1.0.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for pycategories-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b21e66bfa098493dfaa7fcd1f3a6ceabdc4db0dd8c4ab5ba23bd2220cdcb5ecd |
|
MD5 | 536f4f2d6300f79c5b81ffa179e30900 |
|
BLAKE2b-256 | d79f749edbce3d59f9db0fb24ffc1b48b99dcc955a108314e564361801def058 |