Skip to main content

partial-apply

Partial application of functions and method names, supporting placeholder values for positional arguments.

Unlike functools.partial(), placeholder values are supported so that positional arguments for partial application do not need to be supplied solely from left to right. Keyword arguments are handled equivalently to functools.partial(). It is also possible to “partially apply” a method name, producing a function which looks up the method to call on the object supplied as its first argument.

Dependencies:

  • Python 2.7 or 3.4+.

Installation:

  • $ pip install partial-apply

Documentation:

  • Sphinx generated API documentation is available in the docs subdirectory of this repository and is also published on GitHub Pages.

Examples

An example of placeholder use:

from partial_apply import Empty, PartialFn, PartialMethod

isint = PartialFn(isinstance, Empty, int)

This makes a function isint() that takes one positional argument and returns True if it is an int and False otherwise. That is, calling isint(1) is equivalent to calling isinstance(1, int). The supplied positional arguments fill in Empty placeholder slots from left to right before reverting to functools.partial()-style appending.

An example of PartialMethod use:

count_true = PartialMethod('count', True)
count_true((False, True))  # returns 1
count_true([False, True])  # returns 1

This makes a function count_true() that counts the number of True values in a sequence. It looks up the sequence method count on the first argument and calls it with the single argument True. The calls shown are equivalent to (False, True).count(True) and [False, True].count(True). Since count_true() only stores the method name and not the method itself, it works on any type with a count() method.

Like PartialFn, PartialMethod supports placeholder positional arguments and functools.partial()-like keyword arguments.

Release files for partial-apply 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for partial-apply 1.0.0
File Size Uploaded
partial-apply-1.0.0.tar.gz 4.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for partial-apply 1.0.0
File Interpreter ABI Platform
partial_apply-1.0.0-py3-none-any.whl Python 3 none any Details
partial_apply-1.0.0-py2-none-any.whl Python 2 none any Details

Total release size: 15.0 kB

Release files / partial-apply-1.0.0.tar.gz

Download URL partial-apply-1.0.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1241f8c2789f8e01c6171471f19f8bf77fb553ae363d63dabb13c9a4ba286bec
BLAKE2b-256 checksum
How to use checksums
db8d0b978badb6e725ce8c0a2c8f6b87fbe4f04668a9b14f5310fc3e44469f11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release files / partial_apply-1.0.0-py3-none-any.whl

Download URL partial_apply-1.0.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34fde581a8380f025b6386cc15cbb8c3c47c718e88b6312765da6a2ca6c0430d
BLAKE2b-256 checksum
How to use checksums
1fb6ac0316759271f12cf88dce3a667af6a78643646e6d462d753cf0ba311d8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release files / partial_apply-1.0.0-py2-none-any.whl

Download URL partial_apply-1.0.0-py2-none-any.whl
Size 5.2 kB
Tags Python 2
SHA-256 checksum
How to use checksums
477f8b6d8a4019e0b293be72df97225901fe55d8fffc6997ac465f856f0c9444
BLAKE2b-256 checksum
How to use checksums
78dfd8bed299f6a8d0198e22f10cec0f18a9dfa20ba845b0a160c4933013ad4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page