lambda with some syntactic sugar
Project description
Highlambder - there can be only one... lambda to rule them all
Syntactic sugar for Python lambda expressions. Make your anonymous functions shorter, more expressive, and (let's be honest) just more fun.
Image used under fair use, for illustrative and non-commercial purposes. All rights to the character and image belong to their respective owners.
What is Highlambder?
Highlambder lets you write more elegant and compact code by replacing Python’s lambda keyword with something cleaner and more intuitive: a symbolic placeholder that behaves like a function.
You get concise, readable lambdas with operator overloading — no more lambda x: boilerplate.
Installation
pip install highlambder
Quick Examples
from highlambder import L as λ
λ (10) # -> 10
(λ + 5) (10) # -> 15
(λ * 5) (10) # -> 50
(3 + λ * 2) (10) # -> 23
(40 / λ / 5) (2) # -> 4
(10 * λ[1]) ([1, 2, 3]) # -> 20
(-1 + λ * 5 / λ + 1) (13) # -> 5
(λ * 2 + λ * 4 + λ) (10) # -> 70
(λ['A'] + λ['B']) ({'A': 3, 'B': 4}) # -> 7
(λ + λ) (2) # -> 4
("It's a Me, " + λ) ('Mario!') # -> 'It's a Me, Mario!'
Work-in-progress: pandas and NumPy support
import pandas as pd
import numpy as np
from highlambder import L as λ
# pandas:
df = pd.DataFrame({
'A': [1, 1, 2, 2],
'B': [5, 6, 7, 8],
'C': ['banana', 'apple', 'kiwi', 'orange'],
})
# Traditional lambda
assert pd.DataFrame.equals(
df.assign(D=lambda d: d.A + 20),
df.assign(D=λ.A + 20)
)
# String operations
assert pd.DataFrame.equals(
df.assign(D=lambda d: d['C'].str.len() * 2),
df.assign(D=λ['C'].str.len * 2)
)
# NumPy:
assert (λ + λ)(np.int64(2)) == 4
assert (λ.max - λ.min)(np.array([3, 4, 5, 6, 7, 8])) == 5
Limitations (for now)
- Only single-argument functions are supported.
- len(L) is not supported due to Python's limitations on overriding len without a concrete value.
These limitations may be lifted in future versions.
License
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 Distribution
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 highlambder-0.1.0.tar.gz.
File metadata
- Download URL: highlambder-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
560e94488abdb2f1d40b9df736957c0c87e809fccac70f189d38790ba25044cd
|
|
| MD5 |
1e792c02ee5f07718660c546d05fa8aa
|
|
| BLAKE2b-256 |
294f5a834c7f47b2b1738a5f8fbddee9fdc059caf1816bb7caa174c5e808e10b
|
File details
Details for the file highlambder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: highlambder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5dc0635bd6c4a0bdff428d612758691afd37f82bb91edff8a41f7e3d78e26c4
|
|
| MD5 |
12d33db9eb04697ea81e0be8c1d6ec32
|
|
| BLAKE2b-256 |
c476f5c5e2a69200d331375d1673175b46ef7bd4115214397097244f30b47cce
|