Skip to main content

Operator overloading for fast anonymous functions.

Project description

image image image image build image CodeQL CodSpeed Badge image image

A placeholder uses operator overloading to create partially bound functions on-the-fly. When used in a binary expression, it will return a callable object with the other argument bound. It's useful for replacing lambda in functional programming, and resembles Scala's placeholders.

Usage

from placeholder import _     # single underscore

_.age < 18     # lambda obj: obj.age < 18
_[key] ** 2    # lambda obj: obj[key] ** 2

Note _ has special meaning in other contexts, such as the previous output in interactive shells. Assign to a different name as needed. Kotlin uses it, but in Python it is a common short name for an iterator.

_ is a singleton of an F class, and F expressions can also be used with functions.

from placeholder import F

-F(len)        # lambda obj: -len(obj)

All applicable double underscore methods are supported.

Performance

Every effort is made to optimize the placeholder instance. It's 20-40x faster than similar libraries on PyPI.

Placeholders are also iterable, allowing direct access to the underlying functions.

(func,) = _.age  # operator.attrgetter('age')

Performance should generally be comparable to inlined expressions, and faster than lambda. Below are some example benchmarks.

min(data, key=operator.itemgetter(-1))    # 1x
min(data, key=_[-1])                      # 1.3x
min(data, key=lambda x: x[-1])            # 1.6x

Installation

% pip install placeholder

Tests

100% branch coverage.

% pytest [--cov]

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

placeholder-1.5.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distributions

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

placeholder-1.5.1-cp310-abi3-win_amd64.whl (11.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

placeholder-1.5.1-cp310-abi3-win32.whl (10.9 kB view details)

Uploaded CPython 3.10+Windows x86

placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl (12.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl (12.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

placeholder-1.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (12.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

placeholder-1.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (11.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl (8.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl (8.1 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file placeholder-1.5.1.tar.gz.

File metadata

  • Download URL: placeholder-1.5.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for placeholder-1.5.1.tar.gz
Algorithm Hash digest
SHA256 01c0a47b918a3084b3759faeb5e7ab96d0c931e69fc21d38ccb4c701323275f7
MD5 6d944cc8b4da61a1ec1bc2018c354281
BLAKE2b-256 272ab67b87ce4b6331c8ceaadfb3854fe33aa5301291ca4cf07c5df5575782b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1.tar.gz:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: placeholder-1.5.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d00f49f60548fcd1ff3b2777c8350337ac1eec83a5b1611ad2b6b61154ef4d1c
MD5 25c636e8314836faf47a276dcbe2981d
BLAKE2b-256 1f1dbd7e333c565b0169217bdac3cec9851e8b81d3bcb7be0d4a003905483c1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-win_amd64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-win32.whl.

File metadata

  • Download URL: placeholder-1.5.1-cp310-abi3-win32.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 3b95f0258dedcd325e57a2626ba10398f1b1d19068da9941ba49012d580feb88
MD5 64e646cb154d33ba6796d7dec179cf52
BLAKE2b-256 4713b96f11464205aa7c17fb7cf03728090becb1723c638a02bca391fe4c299f

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-win32.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a94361e20872a4f052f14129c16b34a6d9546b52ed0d9b68eed2ae4259aab9d2
MD5 222926000951932e38f10c2e32a26ac2
BLAKE2b-256 bf42a9ba2813145cd84712f2960e104e754c92f4507e532dc079a641ec6740ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 59fe003fcd2e36d0988c30f20f4768536072b619b75d4050c908843a112de35e
MD5 5ac36c9f0e56ec556ca99121abcbbfce
BLAKE2b-256 1affbb634c3303c8b4d9fd445318b6de002826d329083d34634d8600b1936a4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e7b64279d454bd31b7de143d211c1786550cd07f304e207adc148fa8895bd91e
MD5 5a12bd01fc26cc1c3ccecb37c473261f
BLAKE2b-256 64457f915b30ffcbe379a36cec4bcc8859520638dab3ab06efbec14672f1f10b

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 7aff5b2defbff76d1cfb187db0079bfb1033eba31d71122cd736a5f70b27d7f0
MD5 9e1df964e77bbedd24b41c0ccdb34533
BLAKE2b-256 ad83fdb2776bb884bd3b8d030f509d4210ca27ecb89694c3e5d57ce79afbeee7

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86bcaf9d8e0ca17890328f3c43d6c63cd2c3079d77a8566d9a23da4510c32598
MD5 9365e035a257bf1d84cdf4cb4d19c2dd
BLAKE2b-256 b89ab4353b96047424f980d79bd20b876d8b4e557907133cd7010a0aa7f2bd98

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 34c45119aa2e56441148acf3d9a797b8db5ea038ee9ebabf0bcfa37af4aafe65
MD5 974f2e6c7cc3cd4f7fe9cba74a9ad4cd
BLAKE2b-256 dd65c4ed6734d81f6fafeb9d7c1632cf066c368658888c5f55935bdc95fc4b16

See more details on using hashes here.

Provenance

The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl:

Publisher: release.yml on coady/placeholder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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