fx - a functional programming approach
___ | _|_ _ | _|_'_| |_| |_,_|igher-order function coding.
Introduction
TL;DR - YAGNI.
Inspired by Haskell’s rich set of operators, this is an approach to functional programming with operators in Python.
“It’s fun… It’s insane… It’s insanely fun.”
—John Doe
Features
Currying functions with <<, &
Piping output of functions with |
Composing functions with **
Flipping order of arguments of function with ~
and more
Examples
>>> from fx import f
>>> double_all = f(map) << 2 .__mul__ | list
>>> double_all([1, 2, 3])
[2, 4, 6]
>>> double_all |= f(map) << str | ' '.join
>>> double_all([1, 2, 3])
'2 4 6'
>>> sum_upto = 1 .__add__ | f(range) << 1 | sum
>>> sum_upto(100)
5050
>>> parse_hex_str = ~f(int) << 16
>>> parse_hex_str('ff')
255
>>> parse_hex_str('c0ffee')
12648430
>>> # project euler problem 1
>>> euler_p1 = f(range) << 1 | f(filter) << (lambda n: n % 3 == 0 or n % 5 == 0) | sum
>>> 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) << int
>>> euler_p20(10)
27
>>> euler_p20(100)
648
Requirements
CPython >= 2.6
Installation
Install from PyPI:
pip install fx
Install from source, download source package, decompress, then cd into source directory, run:
make install
License
BSD New, see LICENSE for details.
Links
- Documentation:
- Issue Tracker:
- Source Package @ PyPI:
- Mercurial Repository @ bitbucket:
- Git Repository @ Github:
Metadata
Release files for fx 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fx-0.3.tar.gz | 19.3 kB | Without provenance | Details |
Release files / fx-0.3.tar.gz
| Download URL | fx-0.3.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4fcdcae90e42c7f9eeb4233522fff4c6b50639075da4a0faed0c5b300dd11bcc
|
|
BLAKE2b-256 checksum How to use checksums |
9a8903dd35e498c7f9d8e95ba2da6382da5cd825863cc972b4f7cb56921f1ff9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for fx 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.