fx is a Python module for higher-order function coding.
Examples
>>> from fx import f
>>> double_all = f(map) >> double_all([1, 2, 3])
[2, 4, 6]
>>> double_all |= f(map) >> double_all([1, 2, 3])
'2 4 6'
>>> sum_upto = 1 .__add__ | f(range) >> sum_upto(100)
5050
>>> parse_hex_str = ~f(int) >> parse_hex_str('ff')
255
>>> parse_hex_str('c0ffee')
12648430
>>> # project euler problem 1
>>> euler_p1 = f(range) > euler_p1(10)
23
>>> euler_p1(1000)
233168
>>> # project euler problem 20
>>> fact = f(lambda n: 1 if n == 1 else n * fact(n - 1))
>>> euler_p20 = str ** fact | sum ** f(map) >> euler_p20(10)
27
>>> euler_p20(100)
648
Installation
pip install fx
or from the source archive:
make install
Links
Documentation:
http://fx.readthedocs.org/
Issue Tracker:
https://bitbucket.org/pyx/fx/issues/
Source Package @ PyPI:
http://pypi.python.org/pypi/fx/
Mercurial Repoistory @ bitbucket:
https://bitbucket.org/pyx/fx/
Git Repoistory @ Github:
https://github.com/pyx/fx/
Product's homepage
Here are some key features of "fx":
· Currying functions with
Requirements:
· Python