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 iters.iters 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 iters.iters 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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for iterwrapper-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb82e8cb260fd5782a4b4cfcaaa5d07a196286dcd7d421b39ad3e7cd5c1b3ee |
|
MD5 | 0cee04ed8b01cceff66b251a7e2a42f5 |
|
BLAKE2b-256 | 6e42f086b45555fa602d12e008408ee579c158830b2ff05ae3f4cc89810cea87 |