Skip to main content

A lightweight extension of functools.partial

Project description

impartial

A lightweight extension of functools.partial that allows modifying positional and keyword arguments in a functional style. The main idea is that any impartial function gets a method with_<keyword>(value) for every keyword argument which 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

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

impartial-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: impartial-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 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.0.tar.gz
Algorithm Hash digest
SHA256 de74b48587cb1833ed67d4a175b32f0b08e3302017500176b2a2ced18e351e52
MD5 92a0b9c54b63ee11dbd4f9ef1121e534
BLAKE2b-256 a2b8bd1d9a2c8f6c059e4d90c03f6dddfe289326aa71d14fea7625471fae78f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: impartial-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d6078e2ade289de2440fff61454fd7a0b55b754aa22c3f91699505f3256fdb9
MD5 df6a7b6876a9c60bdf19a082864ca588
BLAKE2b-256 0ee189aa944d7e585cb067b38cc498bb8a7064cbc98b2f05e442923aac146009

See more details on using hashes here.

Supported by

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