Operator overloading for fast anonymous functions.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01c0a47b918a3084b3759faeb5e7ab96d0c931e69fc21d38ccb4c701323275f7
|
|
| MD5 |
6d944cc8b4da61a1ec1bc2018c354281
|
|
| BLAKE2b-256 |
272ab67b87ce4b6331c8ceaadfb3854fe33aa5301291ca4cf07c5df5575782b1
|
Provenance
The following attestation bundles were made for placeholder-1.5.1.tar.gz:
Publisher:
release.yml on coady/placeholder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1.tar.gz -
Subject digest:
01c0a47b918a3084b3759faeb5e7ab96d0c931e69fc21d38ccb4c701323275f7 - Sigstore transparency entry: 646701449
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d00f49f60548fcd1ff3b2777c8350337ac1eec83a5b1611ad2b6b61154ef4d1c
|
|
| MD5 |
25c636e8314836faf47a276dcbe2981d
|
|
| BLAKE2b-256 |
1f1dbd7e333c565b0169217bdac3cec9851e8b81d3bcb7be0d4a003905483c1c
|
Provenance
The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on coady/placeholder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-win_amd64.whl -
Subject digest:
d00f49f60548fcd1ff3b2777c8350337ac1eec83a5b1611ad2b6b61154ef4d1c - Sigstore transparency entry: 646701491
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b95f0258dedcd325e57a2626ba10398f1b1d19068da9941ba49012d580feb88
|
|
| MD5 |
64e646cb154d33ba6796d7dec179cf52
|
|
| BLAKE2b-256 |
4713b96f11464205aa7c17fb7cf03728090becb1723c638a02bca391fe4c299f
|
Provenance
The following attestation bundles were made for placeholder-1.5.1-cp310-abi3-win32.whl:
Publisher:
release.yml on coady/placeholder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-win32.whl -
Subject digest:
3b95f0258dedcd325e57a2626ba10398f1b1d19068da9941ba49012d580feb88 - Sigstore transparency entry: 646701470
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 12.0 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a94361e20872a4f052f14129c16b34a6d9546b52ed0d9b68eed2ae4259aab9d2
|
|
| MD5 |
222926000951932e38f10c2e32a26ac2
|
|
| BLAKE2b-256 |
bf42a9ba2813145cd84712f2960e104e754c92f4507e532dc079a641ec6740ad
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
a94361e20872a4f052f14129c16b34a6d9546b52ed0d9b68eed2ae4259aab9d2 - Sigstore transparency entry: 646701478
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 12.5 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59fe003fcd2e36d0988c30f20f4768536072b619b75d4050c908843a112de35e
|
|
| MD5 |
5ac36c9f0e56ec556ca99121abcbbfce
|
|
| BLAKE2b-256 |
1affbb634c3303c8b4d9fd445318b6de002826d329083d34634d8600b1936a4d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
59fe003fcd2e36d0988c30f20f4768536072b619b75d4050c908843a112de35e - Sigstore transparency entry: 646701530
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
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
- Download URL: placeholder-1.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 12.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7b64279d454bd31b7de143d211c1786550cd07f304e207adc148fa8895bd91e
|
|
| MD5 |
5a12bd01fc26cc1c3ccecb37c473261f
|
|
| BLAKE2b-256 |
64457f915b30ffcbe379a36cec4bcc8859520638dab3ab06efbec14672f1f10b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
e7b64279d454bd31b7de143d211c1786550cd07f304e207adc148fa8895bd91e - Sigstore transparency entry: 646701544
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
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
- Download URL: placeholder-1.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 11.9 kB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7aff5b2defbff76d1cfb187db0079bfb1033eba31d71122cd736a5f70b27d7f0
|
|
| MD5 |
9e1df964e77bbedd24b41c0ccdb34533
|
|
| BLAKE2b-256 |
ad83fdb2776bb884bd3b8d030f509d4210ca27ecb89694c3e5d57ce79afbeee7
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl -
Subject digest:
7aff5b2defbff76d1cfb187db0079bfb1033eba31d71122cd736a5f70b27d7f0 - Sigstore transparency entry: 646701564
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 8.5 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86bcaf9d8e0ca17890328f3c43d6c63cd2c3079d77a8566d9a23da4510c32598
|
|
| MD5 |
9365e035a257bf1d84cdf4cb4d19c2dd
|
|
| BLAKE2b-256 |
b89ab4353b96047424f980d79bd20b876d8b4e557907133cd7010a0aa7f2bd98
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
86bcaf9d8e0ca17890328f3c43d6c63cd2c3079d77a8566d9a23da4510c32598 - Sigstore transparency entry: 646701464
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl.
File metadata
- Download URL: placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl
- Upload date:
- Size: 8.1 kB
- Tags: CPython 3.10+, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34c45119aa2e56441148acf3d9a797b8db5ea038ee9ebabf0bcfa37af4aafe65
|
|
| MD5 |
974f2e6c7cc3cd4f7fe9cba74a9ad4cd
|
|
| BLAKE2b-256 |
dd65c4ed6734d81f6fafeb9d7c1632cf066c368658888c5f55935bdc95fc4b16
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
placeholder-1.5.1-cp310-abi3-macosx_10_9_x86_64.whl -
Subject digest:
34c45119aa2e56441148acf3d9a797b8db5ea038ee9ebabf0bcfa37af4aafe65 - Sigstore transparency entry: 646701508
- Sigstore integration time:
-
Permalink:
coady/placeholder@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/coady
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4aedaaeef5e2718c8ee3700c0e8bee8c93eb44a4 -
Trigger Event:
push
-
Statement type: