Skip to main content

Operator overloading for fast anonymous functions.

Project description

A placeholder object 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 when doing functional programming. For example:

  • __[key] == operator.itemgetter(key)

  • __.name == operator.attrgetter(‘name’)

  • (1 + __) == (1).__add__ or partial(operator.add, 1)

  • (__ - 1) == (1).__rsub__ or lambda obj: obj - 1


A composer object extends placeholders with function composition, but at a performance cost. In addition to operator overloading, functions can be supplied explicitly with postfix notation.

  • (___ * 2) + 1 == lambda obj: obj*2 + 1

  • composer(len, math.sqrt) == lambda obj: math.sqrt(len(obj))

  • composer(len) + 1 == lambda obj: len(obj) + 1


__ and ___ are placeholder and composer singletons which can be imported from the module, but each can of course be instantiated and bound to any desired name.

See tests for more example usage. Supported on Python 2.5 or higher, including Python 3.

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-0.4.tar.gz (3.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: placeholder-0.4.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for placeholder-0.4.tar.gz
Algorithm Hash digest
SHA256 b828102abe93b2ed56cb2aa184e2398c47f9a451556362d135672939f1b6ae32
MD5 4745d8b2bcf82b5a0ee8da812089493a
BLAKE2b-256 b8b70b1d204ce9fd37a727989222fccf75dc02566e2dbef1f6eb02a1075da4c0

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