Add .map, .filter and .reduce as list methods
Project description
list_methods
Tired of not having map, filter and reduce as easily available like in Javascript, Java, Kotlin etc? Fear, not this is the class for you.
Installation
pip install list_methods
Use
>>> from list_methods import L
>>> l = L([1,2,3])
>>> plusone = lambda x : x+1
>>> greater_than_noe = lamda x : x > 1
>>> l.map(plus_one).c()
[2,3,4]
>>> l.filter(greater_than_one).c()
[2,3]
>>> l.map(plus_one).map(plus_one).filter(greater_than_one).c()
[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 pipeline 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)
[2,3,4]
>>> l.map(plus_one)
[3,4,5]
TODO
- Write tests
- Write benchmarks
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
list_methods-0.1.0.tar.gz
(14.6 kB
view hashes)
Built Distribution
Close
Hashes for list_methods-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58f8c296bb4e58a58851aa3b88c64a2a9071240d68264c3f3da6a3f0f1176054 |
|
MD5 | df35af12f27087403ec5b0c76bd24def |
|
BLAKE2b-256 | ee775154b3c16ec2dd8fd0268f922051e9db41b855c618b772bf66909390a8bb |