Data structures and utilities for monadic style functional programming.
PyMonad implements data structures typically available in pure functional or functional first programming languages like Haskell and F#. Included are Monad and Monoid data types with several common monads included - such as Maybe and State - as well as some useful tools such as the @curry decorator for defining curried functions. PyMonad 2.0.x represents and almost complete re-write of the library with a simpler, more consistent interface as well as type annotations to help ensure correct usage.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
From a command line run:
pip install PyMonad
Download the project files from https://pypi.org/project/PyMonad/#files and from the project directory run:
python setup.py install
If that doesn’t work you may need to run the following instead.
python3 setup.py install
Clone the project repository:
git clone https://github.com/jasondelaat/pymonad.git
Then from the project directory run setup.py as for the manual build instructions above.
The following example imports the tools module and uses the curry function to define a curried addition function.
import pymonad.tools @pymonad.tools.curry(2) # Pass the expected number of arguments to the curry function. def add(x, y): return x + y # We can call add with all of it's arguments... print(add(2, 3)) # Prints '5' # ...or only some of them. add2 = add(2) # Creates a new function expecting a single arguments print(add2(3)) # Also prints '5'
These tests primarily ensure that the defined monads and monoids obey the required mathematical laws.
On most *nix systems you should be able to run the automated tests by typing the following at the command line.
However, run_tests.sh is just a convenience. If the above doesn’t work the following should:
python3 -m unittest discover test/
Contributors only need to run pylint and pytype over their code and ensure that there are no glaring style or type errors. PyMonad (mostly) attempts to adhere to the Google Python Style Guide and includes type hinting according to PEP 484.
In general, don’t disable pylint or pytype errors for the whole project, instead disable them via comments in the code. See the existing code for examples of errors which can be disabled.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size PyMonad-2.1.0-py3-none-any.whl (25.3 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size PyMonad-2.1.0.tar.gz (18.5 kB)||File type Source||Python version None||Upload date||Hashes View|