Skip to main content

Lamb 🐑: Concise Function Expression in Python

This module introduces a new way to express small functions in a compact and intutive way using a single object called lamb. Any expression in which a lamb appears turns into a function of which lamb is a parameter. Check demo.py to see a demonstration:

from lamb import *
# Primary purpose: Creating small anonymous functions
res = filter(lamb % 5 < 3, range(30))

# Arbitrary arithmetic and boolean operators are allowed:
f   = (lamb ** 2 % 6) - 28 != 5 / 4
f_l = lambda x: (x ** 2 % 6) - 28 != 5 / 4
f(2) == f_l(2) # The two expressions are equivalent

# Empty function calls, index and attribute access are possible as well
g = lamb().x[2] - 3 == None

# Lambs can be chained with other functions using the righshift operator
h = g >> f >> lamb + 2 # make sure the first function is a lamb

# For multi-variable lambs, different lamb names improve clarity
from lamb.vs import * # Imports a, b, c, ..., z
from lamb.l_vs_ import * # Import l_a_, l_b_, .. arbitrary pre- and postfixes are possible
g = (l_a_ - b) * c

# g is now a function of three arguments, or rather: functions returning functions,
# with one argument each (shoutout to Haskell)
g(1)(2)(3) == g(1, 2)(3) == g(1, 2, 3)

# Arguments replace lambs left-to-right. The following will output -3:
g(1, 2, 3)

# Note that `a_ is b_` and `a_ is lamb`; they differ only in their identifier. 
# In other words, the following are equivalent:
g2 = (lamb - lamb) * lamb
g(1, 2, 3) == g2(1, 2, 3)

# Lambs can be nested. Parents inherit un-evaluated lambs from their children.
# For clarity, lambs can be added as placeholder for unevaluated args:
h  = g(1, 2) + g(3) 
h2 = g(1, 2, a) + g(3, a, b)
h(1, 2, 3) == h2(1, 2, 3)

# In a select few cases, this will work, but is discouraged. Use g = lamb >> f instead.
f = lambda x: x + 2 == 5
g = f(lamb)
f(2) == g(2)

Installation

lamb is installable from PyPI:

python -m pip install lamb

Metadata

Release files for lamb 0.0.1.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lamb 0.0.1.post1
File Size Uploaded Provenance Actions
lamb-0.0.1.post1.tar.gz 3.6 kB Without provenance Details for lamb-0.0.1.post1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lamb 0.0.1.post1
File Interpreter ABI Platform Actions
lamb-0.0.1.post1-py3-none-any.whl Python 3 none any Details for lamb-0.0.1.post1-py3-none-any.whl

Total release size: 8.2 kB

Release files / lamb-0.0.1.post1.tar.gz

Download URL lamb-0.0.1.post1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
572e414054b912c868c54298a826455066c130f5349aefe6681421beb32f7d3b
BLAKE2b-256 checksum
How to use checksums
a4785e0cabe1b8ea642cb2d6d23b55d0744152a3431252f502f342a90d4ab914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0

Release files / lamb-0.0.1.post1-py3-none-any.whl

Download URL lamb-0.0.1.post1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fd82e40921dd83320f01d9dbcb4bcd2e319810e7fca3e8be40d8b352b45ce11
BLAKE2b-256 checksum
How to use checksums
0cce7313985ea4369186f0c6a2caa9caec068e5bafe3b2d6e3bdab9fe4d74882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0

Security for lamb 0.0.1.post1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page