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.

Scroll down for examples.

Classes

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.2.0

  • Added first(), which gives you the first value in Iterable, with an optional default if no values exist
  • Added mapmany(), which functions like map, except it expects more than one output for each item of Iterable

0.1.0

  • First release!
  • Iterable class with equivalent built-in functions related to iterables

Indices and tables