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 iterwrapper.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
iterwrapper-0.1.1.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for iterwrapper-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b27d37f97fc4f660cb0221d352da5b676113c4d3b3420417b649041b9d140b47 |
|
MD5 | d2b1d3221c004cec8a6cdc74ce9f8467 |
|
BLAKE2b-256 | d696b0047a0812a292a0d7cdf6f4d081ab5ece11f8c0a36c32841be096e2f41f |