Skip to main content

Operator overloading for fast anonymous functions.

Project description

image image image image image image image 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.

However, there is slight overhead (in CPython) in making an object callable. Placeholders with single operators can access the func attribute directly for optimal performance.

_.age.func         # operator.attrgetter('age')
_[key].func        # operator.itemgetter(key)

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

min(data, key=operator.itemgetter(-1))    # 22.7 ms
min(data, key=_[-1])                      # 25.9 ms
min(data, key=lambda x: x[-1])            # 27.2 ms

Installation

% pip install placeholder

Tests

100% branch coverage.

% pytest [--cov]

Changes

1.2.1

  • setup fix

1.2

  • Python >=3.6 required
  • Optimized partial implementation

1.1

  • Additional unary functions

1.0

  • Removed __ (double underscore)
  • Variable arguments of first function
  • Method callers and multi-valued getters

0.7

  • Deprecated __ (double underscore)

0.6

  • Optimized composite functions
  • Renamed to _ (single underscore) for consistency

0.5

  • Unary operators
  • __call__ implements methodcaller
  • __getitem__ supports only single argument
  • Improved error handling
  • composer object deprecated in favor of optimized F expression

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.2.1.tar.gz (6.6 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.2.1-cp39-cp39-win_amd64.whl (10.3 kB view details)

Uploaded CPython 3.9Windows x86-64

placeholder-1.2.1-cp39-cp39-manylinux2014_x86_64.whl (20.7 kB view details)

Uploaded CPython 3.9

placeholder-1.2.1-cp39-cp39-manylinux1_x86_64.whl (20.7 kB view details)

Uploaded CPython 3.9

placeholder-1.2.1-cp39-cp39-macosx_10_14_x86_64.whl (7.0 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

placeholder-1.2.1-cp38-cp38-win_amd64.whl (10.1 kB view details)

Uploaded CPython 3.8Windows x86-64

placeholder-1.2.1-cp38-cp38-manylinux2014_x86_64.whl (20.6 kB view details)

Uploaded CPython 3.8

placeholder-1.2.1-cp38-cp38-manylinux1_x86_64.whl (20.6 kB view details)

Uploaded CPython 3.8

placeholder-1.2.1-cp38-cp38-macosx_10_14_x86_64.whl (6.9 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

placeholder-1.2.1-cp37-cp37m-win_amd64.whl (10.0 kB view details)

Uploaded CPython 3.7mWindows x86-64

placeholder-1.2.1-cp37-cp37m-manylinux2014_x86_64.whl (19.9 kB view details)

Uploaded CPython 3.7m

placeholder-1.2.1-cp37-cp37m-manylinux1_x86_64.whl (19.9 kB view details)

Uploaded CPython 3.7m

placeholder-1.2.1-cp37-cp37m-macosx_10_14_x86_64.whl (6.8 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

placeholder-1.2.1-cp36-cp36m-win_amd64.whl (10.0 kB view details)

Uploaded CPython 3.6mWindows x86-64

placeholder-1.2.1-cp36-cp36m-manylinux2014_x86_64.whl (19.0 kB view details)

Uploaded CPython 3.6m

placeholder-1.2.1-cp36-cp36m-manylinux1_x86_64.whl (19.0 kB view details)

Uploaded CPython 3.6m

placeholder-1.2.1-cp36-cp36m-macosx_10_14_x86_64.whl (6.8 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: placeholder-1.2.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1.tar.gz
Algorithm Hash digest
SHA256 9ce511bd1e7fbaac380e9884fd023c947fa020cd8e51304a7efa2aeb65ca30da
MD5 2a41577bdc406cb5d4df142b98a0b2a4
BLAKE2b-256 a27e43e227bb43b1f7f1be365aa81ab3d4e6732def7a187f0fac0c56b130db0c

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for placeholder-1.2.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4a4464ed5ec7ffd0533e4ff4ceb9faf24d41a467012479f757e7409dacb7925d
MD5 d2a92997a12668a53351c299c1d2013a
BLAKE2b-256 c8816bee084c287dbe2223f429cdbd304e0a4ee8f9649de8446ddbc619e93925

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17d159525f16c569a4652f5e329c24f1cf2ac0f798f5eed191bfb5c475c3e15f
MD5 2153032923ec4dbaf38d652fe7c09818
BLAKE2b-256 79d9938cd70b88faba1741ded62545e5caeb1bd6ade950c4d5b058e309778c85

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f348264e332c0a0bb35c506f1f05d71e5f53e63b54851bfbe6b2444951699003
MD5 6ff12a0378c1223f692b68460ff39b41
BLAKE2b-256 f680e1140cf575470abdaf66e19e37c21db5e598dac246504d77c231e888d138

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5db8733105324e4cf90c5f84f0f01ba83109f8cf13e8395f6c175d9c01557e1b
MD5 95ff135a6fcf31f0ced6ebcc0ad221b4
BLAKE2b-256 273099a5dc64f4818020c3758e7432b4fec11064551ab96cc11eb238f67e297a

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.7

File hashes

Hashes for placeholder-1.2.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 55c37c6a0cad5b86cdad96201f4e594ce1f957c6b3fbff80aecb36022815f3ae
MD5 95dbd629fb74abe3acc65fc0ca65b42a
BLAKE2b-256 ff491f95f0d25f8bf4031104a28c18c6d424322467b0661963778f650408183d

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5275649b161b8bd7b840ce061966623dea390beef0c54276d0df77ed082de14b
MD5 0f82143dde0d8189d639e85403689aa1
BLAKE2b-256 612a344a8fd9eebf6d38a3a0a5a27670c5f75dd8ed55cc8f4dff0627ea39a5d5

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 66966972f6ba8de8d9446dd1fe2bd7f4b11cded046207c0738b3abd611421ea9
MD5 816b96bf7ccd76a1f6337e3b63722bd2
BLAKE2b-256 611ff163749a9be0d8cbf096ac133bde52029ec0b16b0a2615a51d23c450bb43

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for placeholder-1.2.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 77903d35075fb4e9f2b4d1238ba41e5cc7872e0ce3dd0963244b94db701200cb
MD5 4ef827b52f132aae9cb2a8224fc5616b
BLAKE2b-256 bfda662b9b2ae80d475d02a3bd67331a9267c9a987496226cd1d8efd5850a5ac

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.9

File hashes

Hashes for placeholder-1.2.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 dbe1b2a2060703ebd4c172b97e3bd5d1a32bcca390b560ccceac5a890160c555
MD5 6c81ccd9a32dd1e7070ceab729e7b15f
BLAKE2b-256 6db92ad2e801e287a94b2eecd6053948dbabfbf1e04639f767e2e17894aac0d0

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ccc4d232f0b0450bef9628d4fc097db1d0a51746a43911d895e04635195cc1f
MD5 f6d0f2d1a5030786ef10ceb8d49d287f
BLAKE2b-256 ef3ebcb12fe62d1f8c198df979c4e658069c654d8bfef025fdd79ddfa4d9bcd7

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 10c50c98f15ef6b094eedf02cf0aed6dbba1be190f4ff403c2c2d7349bceda1b
MD5 78b96a3fe07e78a3748c0cbb6aa86811
BLAKE2b-256 5a29ff24f9da9dc512e1298046ec297906a4a486fc0583b0d9a0c5b5e87a15eb

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.10

File hashes

Hashes for placeholder-1.2.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e457193be498917a3ca6bdf51e5c3f933b774cd81b07227f885f9970d95a3f4c
MD5 ebba53142d3d539a64f81f4ad85190fb
BLAKE2b-256 e348a38913f09da24bb10005b8d27e855d313355a81bb04f46db7ac880b262a7

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.8

File hashes

Hashes for placeholder-1.2.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 857b84590f7b0440b607dd39bcce05a0412ed599d221f0de50105de3bd8cae6f
MD5 931600afae6d448af70f3594082d788b
BLAKE2b-256 30541b4638d973e109eb36881e8dfc634edceda440f14a2de3ebf52238598d49

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c3e23c3ec7db5c71fd34bd05b0d0ca7546a0d4beea5f6e3b4de05fd339f68abe
MD5 8cd7027adcb5f2d869a5009a60ee7c57
BLAKE2b-256 803907b7fedcf9ba9b058f93719497ec3f3b6a02423f9b6135553fe81e7d67e0

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for placeholder-1.2.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 18340ad6c63356bbbd52b10abde1f05442a7c6b1a9dab7f487447e0b19acb250
MD5 5418372d039e39637ab1d367dcb2113c
BLAKE2b-256 c4e696c50389cce6cfef330bddf3a5391833fdbe64b84bd7c1b349ee6a5e5844

See more details on using hashes here.

File details

Details for the file placeholder-1.2.1-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: placeholder-1.2.1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.13

File hashes

Hashes for placeholder-1.2.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 05de0689aa710c6754919c16946b4414aa54c932b1b0b59d196210df12bebc29
MD5 a0484f8988de6171ae93f622f78ebeaf
BLAKE2b-256 bb4b5311712454ce46de24f601ea01c4ceb3ea22dff10f59ec34bfbd8f77c62c

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