What is this?
A better python lambda syntax for your anonymous function needs.
Write a = (x) > x instead of a = lambda x: x. See below for syntax caveats.
Get started immediately: pip install lambdazen
from lambdazen import zen
def otherfunc(*args):
print sum(args)
# The zen decorator allows you to define lambdas with a better syntax
@zen
def example():
example.epic = (x, y, z) > otherfunc(x, y, z)
# Multiline lambdas are a tuple or list of statements
# The assignment operator inside is << instead of =
# The last statement is the return value
example.multiline = (x, y, z) > (
s << otherfunc(x, y, z),
s
)
# Call function so the lambdas are bound to function attributes
example()
example.epic(1,2,3)
>>> 6
example.multiline(1,2,3)
>>> 6
Caveats
better lambdas can only be defined in a function with the @zen attribute
any other code in this function will be executed, it’s best to use the function as a container of lambdas
How does it work
TLDR; Runtime in-memory source rewriting and recompilation
Additional Examples
from lambdazen import zen
# Lambdas don't need to be bound to the function
@zen
def normalizeString(nS):
transforms = [
(s) > s.strip(),
(s) > s.lower(),
(s) > s.replace(' ', '_')]
apply_all = (transforms_list, s) > (
is_done << (len(transforms_list) == 0),
current_transform << transforms_list[0] if not is_done else None,
remaining_transforms << transforms_list[1:] if not is_done else None,
current_transform(apply_all(remaining_transforms, s)) if not is_done else s)
return apply_all(transforms, nS)
normalizeString("Abraham Lincoln")
>>> "abraham_lincoln"
Metadata
Release files for lambdazen 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lambdazen-0.1.7.tar.gz | 3.8 kB | Without provenance | Details for lambdazen-0.1.7.tar.gz |
Release files / lambdazen-0.1.7.tar.gz
| Download URL | lambdazen-0.1.7.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7bb135de9d96853185b13bae07c95b21f0ac7d0ac2750b9605d616f89999930
|
|
BLAKE2b-256 checksum How to use checksums |
0b6bf8a72861c9dc87bb615a9b4c803665c5c2f48528b81149ea4d6a9f7488ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for lambdazen 0.1.7
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.