https://github.com/jferard/yamft
YAMFT (Yet another `more-functools`) is another functional library for Python
https://github.com/jferard/yamft
functional functional-programming list-comprehension more tools
Last synced: about 1 month ago
JSON representation
YAMFT (Yet another `more-functools`) is another functional library for Python
- Host: GitHub
- URL: https://github.com/jferard/yamft
- Owner: jferard
- License: gpl-3.0
- Created: 2019-02-01T20:38:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-31T11:54:45.000Z (over 6 years ago)
- Last Synced: 2025-03-10T12:56:17.335Z (8 months ago)
- Topics: functional, functional-programming, list-comprehension, more, tools
- Language: Python
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
|Build Status| |Code Coverage|
YAMFT (Yet another `more-functools`)
====================================
Copyright (C) J. Férard 2019
YAMFT is another functional library for Python.
Goals
-----
YAMFT doesn't try to mimic Haskell, but rather tries to improve Python functional skills. It targets two main domains:
* `list` and `dict` comprehensions: YAMFT aims to provide functions that will help write more powerful list and dict comprehensions.
* `map`: YAMFT aims to provide helpers to write maps.
But the main goal of YAMFT is... fun. Python is not a functional language, but it's sometimes amusing to use functional idioms to express some lists.
Tricky list comprehensions
~~~~~~~~~~~~~~~~~~~~~~~~~~
List comprehension are very powerful, and sometimes we want them to be even more powerful. This
leads to some weird constructions. YAMFT aims to provide helpers for writing those list comprehensions.
Functional paradigm in Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It should be obvious for everyone that Python is not a pure functional language
like Haskell, and that the Python code is often more readable and efficient
when we **do not** use the functional paradigm. Tough, I find that functional
programming is sometimes beautiful.
Method
------
Functional style in Python is often cumbersome:
>>> map(lambda x:x*x*x, range(5))
[0, 1, 8, 27, 64]
is worse than:
>>> [x*x*x for x in range(5)]
[0, 1, 8, 27, 64]
But this is more disputable when you compare:
>>> [str(x) for x in range(5)]
['0', '1', '2', '3', '4']
with:
>>> list(map(str, range(5)))
['0', '1', '2', '3', '4']
I prefer the latter. The main issue is the lambda syntax. Hence, YAMFT aims to provide plug and play curryfied functions to avoid lambdas.
Installation
------------
Needs Python 3.7
Just ``git clone`` the repo:
.. code-block:: bash
> git clone https://github.com/jferard/yamft.git
Test
----
.. code-block:: bash
> pytest --doctest-modules
> pytest test/*
Help
----
Functions are not first class citizens in Python. You can't give them a docstring when they are defined by an assignment (e.g. `fst = operator.itemgetter(0)`). YAMFT has a special `yamft_help` function to handle this case:
>>> yamft_help(fst) # doctest:+ELLIPSIS
Help on fst:
...