Typed lambdas that are short and readable
Project description
Write short and fully-typed lambdas where you need them.
Features
- Allows to write
lambdas as_ - Fully typed with annotations and checked with
mypy, PEP561 compatible - Has a bunch of helpers for better composition
- Easy to start: has lots of docs, tests, and tutorials
Installation
pip install lambdas
We also recommend to use the same mypy settings we use.
Examples
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']))
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:
scores = [
{'name': 'Nikita', 'score': 2},
{'name': 'Oleg', 'score': 1},
{'name': 'Pavel', 'score': 4},
]
print(sorted(scores, key=_['score']))
It might really save you a lot of effort,
when you use a lot of lambda functions.
Like when using returns library.
Work in progress:
_.some_attributeis not supported yet, because we need a complexmypyplugin for this_.method()is not supported yet for the same reasonTypedDicts 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 lamdbas in these cases.
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 lambdas-0.1.0.tar.gz.
File metadata
- Download URL: lambdas-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.4 Darwin/18.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a595cfbcea23bf7295a821563044785d0dc843b39d21ccaee5c3a79afe79e140
|
|
| MD5 |
7bcb33cc74df722deb1843734f447908
|
|
| BLAKE2b-256 |
ae8efca52d7944063d05659382921110946272feec474123b954821a4e4e8fcb
|
File details
Details for the file lambdas-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lambdas-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.4 Darwin/18.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b197d7cf464b9733944cf9b9cf73d05d934b19eaf0c32fc04a9e7dd25b5ce321
|
|
| MD5 |
e66444961c6c85c27e9515ce80d1bf19
|
|
| BLAKE2b-256 |
6982366db987b7c5ec36cb0b4b78211085ce954e669d6e2fc7a67ccabe973f81
|