A lightweight extension of functools.partial
Project description
impartial
impartial is a lightweight extension of functools.partial that allows modifying positional and keyword arguments in a functional style.
The main idea is that any function wrapped with impartial
gets a method with_<keyword>(value)
for every keyword argument of that function.
Each with_<keyword>(value)
method returns a new impartial
function with that keyword being modified.
>>> import impartial
>>> @impartial
... def power(x, exponent):
... return x ** exponent
...
>>> power
impartial(<function power at 0x10d54e790>)
>>> square = power.with_exponent(2) # behaves like functools.partial(square, exponent=2)
>>> square
impartial(<function power at 0x10d54e790>, exponent=2)
>>> square(3)
9
Features:
- the
with_<keyword>(value)
methods can be arbitrarily chained impartial
functions are immutable: any "modification" of arguments returns a newimpartial
function- very lightweight (~50 LOC and no dependencies)
- fully compatible with functools.partial (
impartial
is a subclass offunctools.partial
) - can be used as a decorator
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
impartial-0.1.1.tar.gz
(6.8 kB
view details)
Built Distribution
impartial-0.1.1-py3-none-any.whl
(11.1 kB
view details)
File details
Details for the file impartial-0.1.1.tar.gz
.
File metadata
- Download URL: impartial-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdd71eb2683b7518753fd6ce31ea1519b64bc571a2c590986e088218b33a5670 |
|
MD5 | 605cd8e7e06d27b4c93eb3127acf7f93 |
|
BLAKE2b-256 | dc769a83a30285f4a8aecca6e71752a51817fad238a4e6996ab484f2f5385b5e |
File details
Details for the file impartial-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: impartial-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 650b4bfbb1112986b706a0354d5469ae6276959f2ef21ea09a622487767505a1 |
|
MD5 | 86ecdc6af4f31de095d6a16cde8f622b |
|
BLAKE2b-256 | 953a641b9ad421ca3f2a0be85ee0d874f473d791f1ac9871406de88fe30b9790 |