SkillAgentSearch skills...

Placeholder

Operator overloading for fast anonymous functions.

Install / Use

/learn @coady/Placeholder
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

image image image image build image CodeQL CodSpeed Badge image ty

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.

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.

_ 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. Some methods coerce types: len, bool, in.

Performance

The placeholder instance leverages functools.partial and Placeholder for optimization. It is significantly faster than similar libraries on PyPI.

Performance should generally be comparable to inlined expressions, and faster than lambda. There is an optional legacy C extension which provides a small speedup for right-bound functions in Python <3.14 only.

Placeholders are provisionally iterable, allowing access to the underlying function and bound args.

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

Installation

pip install placeholder

Tests

100% branch coverage.

pytest [--cov]
View on GitHub
GitHub Stars51
CategoryDevelopment
Updated17d ago
Forks5

Languages

Python

Security Score

85/100

Audited on Mar 10, 2026

No findings