
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Write short and fully-typed lambda
s where you need them.
lambda
s as _
mypy
, PEP561 compatiblepip install lambdas
You also need to configure mypy
correctly and install our plugin:
# In setup.cfg or mypy.ini:
[mypy]
plugins =
lambdas.contrib.mypy.lambdas_plugin
We recommend to use the same mypy
settings we use.
Imagine that you need to sort an array of dictionaries like so:
>>> scores = [
... {'name': 'Nikita', 'score': 2},
... {'name': 'Oleg', 'score': 1},
... {'name': 'Pavel', 'score': 4},
... ]
>>> print(sorted(scores, key=lambda item: item['score']))
[{'name': 'Oleg', 'score': 1}, {'name': 'Nikita', 'score': 2}, {'name': 'Pavel', 'score': 4}]
And it works perfectly fine. Except, that you have to do a lot of typing for such a simple operation.
That's where lambdas
helper steps in:
>>> from lambdas import _
>>> scores = [
... {'name': 'Nikita', 'score': 2},
... {'name': 'Oleg', 'score': 1},
... {'name': 'Pavel', 'score': 4},
... ]
>>> print(sorted(scores, key=_['score']))
[{'name': 'Oleg', 'score': 1}, {'name': 'Nikita', 'score': 2}, {'name': 'Pavel', 'score': 4}]
It might really save you a lot of effort,
when you use a lot of lambda
functions.
Like when using returns
library.
We can easily create math expressions:
>>> from lambdas import _
>>> math_expression = _ * 2 + 1
>>> print(math_expression(10))
21
>>> complex_math_expression = 50 / (_ ** 2) * 2
>>> print(complex_math_expression(5))
100.0
Work in progress:
_.method()
is not supported yet for the same reasonTypedDict
s are not tested with __getitem__
__getitem__
does not work with list and tuples (collections), only dicts (mappings)For now you will have to use regular lamdba
s in these cases.
FAQs
Typed lambdas that are short and readable
We found that lambdas demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.