Pyiterable API Documentation¶
Python comes with some nice built-in methods for operating on iterables, but it can get messy really quickly if you want to transform an iterable multiple times. Write more expressive code by chaining built-in transformations with this module.
The module is available on PyPI via pip:
pip install pyiterable
Examples below.
Details¶
Inspired by:
Instead of:
values = ["1", "2", "5", "9"]
to_int = map(lambda x: int(x), values)
filtered = filter(lambda x: x > 4)
sum = reduce(lambda a, b: a + b, to_int)
or:
values = ["1", "2", "5", "9"]
sum = reduce(
lambda a, b: a + b,
filter(
lambda x: x > 4,
map(lambda x: int(x), values)
)
)
do this:
from pyiterable import Iterable
...
values = Iterable(["1", "2", "5", "9"])
sum = (values
.map(lambda x: int(x))
.filter(lambda x: x > 4)
.reduce(lambda a, b: a + b)
)
Release¶
0.4.0
- Bug fix; new
Iterableobjects should no longer mutate if theiterablepassed into the constructor is mutated - Added more sequence-like functionality:
get(),last(),skip(), andtake() - Added
contains(),single(), andis_empty() - Added
filter_bykeyword parameter to replacefunctionforfirst(), asfilter_byis more self-explanatory
0.3.1
- Added support for Python 3.5
- Removed support for Python 3.2
0.3.0
- Added set-like functionality, including
difference(),intersection(),symmetric_difference(), andunion(). - Added
concat()as an alternative tounion() - Added
distinct() - Added frozenset support (
to_frozenset())
0.2.0
- Added
first(), which gives you the first value inIterable, with an optional default if no values exist - Added
mapmany(), which functions like map, except it expects more than one output for each item ofIterable
0.1.0
- First release!
- Iterable class with equivalent built-in functions related to iterables