A wrapper for FP style iterator manipulation
Project description
IterWrapper
This is a wrapper for python iterators to give it a style like those in Rust among with other methods, to improve the consistency and code readablity of iterator manipulation.
A example for this is something like :
from iterwrapper import IterWrapper as iw
l = (
iw(range(0,10))
.map(lambda x:x+1)
.filter(lambda x:x%2==0)
.fold(lambda c, x: c+x**2, d=0)
)
print(l) # 220 = 2^2 + 4^2 + 6^2 + 8^2 + 10^2
comparing to the equivalent representation in vanilla python :
l = sum(map(lambda x: x**2, filter(lambda x:x%2==0, map(lambda x: x+1, range(0,10)))))
# or
r = range(0, 10)
m = map(lambda x: x+1, r)
f = filter(lambda x: x%2==0, m)
c = map(lambda x: x**2, f)
l = sum(c)
Another one:
from iterwrapper import IterWrapper as iw
l = (
iw(range(0,10))
.map(lambda x: x+1)
.filter(lambda x: x%2==0)
.map(str)
.collect(', '.join)
)
print(l) # "2, 4, 6, 8, 10"
# Comparing to
l = ', '.join(map(str, filter(lambda x: x%2==0, map(lambda x: x+1, range(0,10)))))
# or
r = range(0, 10)
m = map(lambda x: x+1, r)
f = filter(lambda x: x%2==0, m)
ms = map(str, f)
l = ', '.join(ms)
The main goal of this only is to be a convenient wrapper to manipulate iterators, so it comes with high compatibility since most of the method is done by accessing the wrapped iterator, and most of the method just use the wrapper as a container.
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
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 iterwrapper-0.1.4.tar.gz.
File metadata
- Download URL: iterwrapper-0.1.4.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2dd1e5a55935a0ce151912524de1781d2aa9cb1fda3e2424fb403ff857f63d9
|
|
| MD5 |
fb3d0aaad7a2a9fe10ad1cedaf69ac57
|
|
| BLAKE2b-256 |
8214e4ece51ce39f268d63cb7d9197478b3ff971e156f2da7d2d5e17396c0d4c
|
File details
Details for the file iterwrapper-0.1.4-py3-none-any.whl.
File metadata
- Download URL: iterwrapper-0.1.4-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3296d81fa2e558734f572617487fb6be3e2af12af2776899dd29d2154ffdba5
|
|
| MD5 |
52e2d67b5fa0d9f1cdad244390d44fc3
|
|
| BLAKE2b-256 |
5a6026365ea984386b255e9a4b5c6fa014ba668b14251e0728e2a9a8cc5f8ad0
|