Skip to main content

A lightweight extension of functools.partial

Project description

impartial

build PyPI PyPI - Python Version Licence

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 new impartial function
  • very lightweight (~50 LOC and no dependencies)
  • fully compatible with functools.partial (impartial is a subclass of functools.partial)
  • can be used as a decorator

To install this package, run:

pip install impartial

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.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

impartial-0.1.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file impartial-0.1.2.tar.gz.

File metadata

  • Download URL: impartial-0.1.2.tar.gz
  • Upload date:
  • Size: 7.2 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

Hashes for impartial-0.1.2.tar.gz
Algorithm Hash digest
SHA256 24bcad4a882bcca91bec484b4b36e1e183968a7c70b7dae8439b49ea0dfccddd
MD5 74df921d0dbb076bda092dcc169c073b
BLAKE2b-256 82aa04b8cec5fa45f15e0aa06a6d9f0d3ecfe618819df20a71008f47b770f504

See more details on using hashes here.

File details

Details for the file impartial-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: impartial-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 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

Hashes for impartial-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 016e84d202f495de99fb01fa6824796e32493786f0fb671a988e7c7e8560badc
MD5 d5fdddcf31dc1ac2b823ada53c879817
BLAKE2b-256 9efeee430d7be1f83d8896a693a1d1b774f4ab60b994393d6ba7cc93cfebfc0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page