forbiddenfp
Summary
Functional-Programming (FP) in a forbidden way:
You can turn arbitrary function into postfix notation in favor of function chaining.
And the library provides many useful patches for builtin/itertools functions.
Install
Compatible with Python 3.7+
pip install forbiddenfp
Examples
# objects are already patched at import time
import forbiddenfp
"abc".print().len() # print out "abc", then return 3
"abc".then(lambda s: s * 2).filter(lambda s: s == "b").join() # "bb"
# A more complex one (examples/word_count.py)
("./lorem_ipsum.txt"
.with_open(lambda path, f: f.read().also(print(f"Reading {path}")))
.then(lambda s: s.split(" "))
.counter()
.print())
See more ./examples.
_unpack
For every higher-order-function chained, we provide an _unpack version as well.
e.g. [(1, 2), (3, 4)].sum(lambda x: x[0] * x[1])
can also be called as [(1, 2), (3, 4)].sum_unpack(lambda x, y: x * y)
Why Functional Programming
Separate out control structs (which are functions provided by library) from business logic (which are lambda functions supplied to fill the control structs).
So we can have a clearer scope, and separate concerns, when we want to change on either side of things.
if ...andif ... else ...are modeled by Maybe/Either monads.while ...andfor ... in ...are generator/iterators. Additionally, stop-early behavior istakewhileof the sequence.
Philosophically, think more in def transform(old_state) -> new_state, rather than state = modify(state).
What About Auto-completion?
This library is almost an embedded Domain Specific Language (DSL) in Python.
It is understandable that users aren't familiar with what is available without auto-completion features in IDEs.
So we leverage the stub file to provide type hints for the builtin object type, which IntelliJ/PyCharm/VsCode all support.
In order to find where to stub, open your IDE and Python project/file, type object to get a class, CTRL/CMD + Click and use
"Find Definition" feature to get to the stub file of your IDE plugin.
Then copy/paste src/forbiddenfp/__init__.py under class object stub.
Note that for IntelliJ/Pycharm, once you CTRL + Click on object, you would need to click on the little icon below
to get to the actual stub file. Append content there.
Warning
This library patches builtin object (and hence ALL classes),
with hacks around CPython API (provided by forbiddenfruit),
so consider this NSFW (Not Safe For Work).
Known Issues
None doesn't work well with chained keyword arguments.
import forbiddenfp
None.apply(print) # works
None.apply(func=print) # doesn't work
Metadata
Release files for forbiddenfp 0.9.9.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 | Actions |
|---|---|---|---|---|
| forbiddenfp-0.9.9.3.tar.gz | 7.9 kB | Without provenance | Details for forbiddenfp-0.9.9.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| forbiddenfp-0.9.9.3-py3-none-any.whl | Python 3 | none | any | Details for forbiddenfp-0.9.9.3-py3-none-any.whl |
Total release size: 15.9 kB
Release files / forbiddenfp-0.9.9.3.tar.gz
| Download URL | forbiddenfp-0.9.9.3.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40e179f232cc32177aa0a3178e70a3cdb2a38f7ec8428b98cd4620b2c6542e5c
|
|
BLAKE2b-256 checksum How to use checksums |
ab4d3f8de2487e37101a7275fa434b75777f4619026cea59363320429a536ed1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.16
|
Release files / forbiddenfp-0.9.9.3-py3-none-any.whl
| Download URL | forbiddenfp-0.9.9.3-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db1a981a94066d107720834c71e6f28646083e36bd26a963a48a43152edf4334
|
|
BLAKE2b-256 checksum How to use checksums |
430c0ff73c0aa49de7ef38d01ef05f35c9439d4a0a756e0ccf2a440fc898277d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.16
|
Security for forbiddenfp 0.9.9.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.