list_methods [Experimental]
Tired of not having map, filter and reduce easily available like in Javascript, Java, Kotlin, etc? Fear not, this is the package for you(sort of).
Experimental package adding .map(), .filter() and .reduce() as list methods. Made mostly as PoC showing how the Python language can be extended in some way.
Installation
pip install list_methods
Use
>>> from list_methods import L
>>> l = L([1,2,3])
>>> plus_one = lambda x : x+1
>>> greater_than_one = lamda x : x > 1
>>> l.map(plus_one).c()
L([2,3,4])
>>> l.filter(greater_than_one).c()
L([2,3])
>>> l.map(plus_one).map(plus_one).filter(greater_than_one).c()
L([3,4,5])
>>> agg_plus = lambda x,y: x+y
>>> l.reduce(agg_plus)
6
Gotchas
Remember to call the .c() method since this resets the object so it can be used further. This is not necessary when ending the chain of operations with .reduce()
Javascript
> l = [1,2,3]
> l.map(x => x +1)
[2,3,4]
> l.map(x => x +1)
[2,3,4]
list_methods - Python
>>> l.map(plus_one)
L([2,3,4])
>>> l.map(plus_one)
L([3,4,5])
Gotcha #2
- The list needs to be copied when instantiating the object so it can be reset for other use. In the future one should maybe add a flag to skip this list copy if the list is only used in one place.
TODO
- Write tests
- Write benchmarks
- Test a implementation where a new instance of the class is returned instead of self
Metadata
Release files for list-methods 0.1.3
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 |
|---|---|---|---|---|
| list_methods-0.1.3.tar.gz | 15.2 kB | Without provenance | Details for list_methods-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| list_methods-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for list_methods-0.1.3-py3-none-any.whl |
Total release size: 30.7 kB
Release files / list_methods-0.1.3.tar.gz
| Download URL | list_methods-0.1.3.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dca2452b1a1114bc7da20e2681720a25fafd4c3622b848b216d1d7b9abf653cd
|
|
BLAKE2b-256 checksum How to use checksums |
7c1f2f6eb2022a2d95bbf99e2462c6a55eafda2c57144b3b82d563619ce5f920
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Release files / list_methods-0.1.3-py3-none-any.whl
| Download URL | list_methods-0.1.3-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a797bba84743f831f5b8f1be3cdb2bbf378cc79c7184bca4f6f83c6d526231c5
|
|
BLAKE2b-256 checksum How to use checksums |
a9b49ecd5ef8f6b130850c5b303874fcde90d3b4eaaa57184c9bbcee775fda39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Security for list-methods 0.1.3
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.