Skip to main content

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

Project description

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.

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

partial-apply-1.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distributions

partial_apply-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

partial_apply-1.0.0-py2-none-any.whl (5.2 kB view details)

Uploaded Python 2

File details

Details for the file partial-apply-1.0.0.tar.gz.

File metadata

  • Download URL: partial-apply-1.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for partial-apply-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1241f8c2789f8e01c6171471f19f8bf77fb553ae363d63dabb13c9a4ba286bec
MD5 1f2f0afb1cb11d8170fa021e273cf7f3
BLAKE2b-256 db8d0b978badb6e725ce8c0a2c8f6b87fbe4f04668a9b14f5310fc3e44469f11

See more details on using hashes here.

File details

Details for the file partial_apply-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: partial_apply-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for partial_apply-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34fde581a8380f025b6386cc15cbb8c3c47c718e88b6312765da6a2ca6c0430d
MD5 b9c9bf5aace927e027aa2436583f87a7
BLAKE2b-256 1fb6ac0316759271f12cf88dce3a667af6a78643646e6d462d753cf0ba311d8f

See more details on using hashes here.

File details

Details for the file partial_apply-1.0.0-py2-none-any.whl.

File metadata

  • Download URL: partial_apply-1.0.0-py2-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2
  • Uploaded using 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

File hashes

Hashes for partial_apply-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 477f8b6d8a4019e0b293be72df97225901fe55d8fffc6997ac465f856f0c9444
MD5 714ff7c883ebf6ab4ae5c96b2ebe720b
BLAKE2b-256 78dfd8bed299f6a8d0198e22f10cec0f18a9dfa20ba845b0a160c4933013ad4f

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