Skip to main content

Inspired by Java 8 streams, simple list processing

Project description

Inspired by Java 8’s streams, this Python module provides a fluent syntax for manipulating and querying Python lists. It’s called lazy-streams because it lazy evaluates the requests to increase performance and decrease resource requirements. Because of the lazy evaluation, lazy-streams can work on really large data sets with relatively small delays.

Here’s a quick example:

>>> from lazy_streams import stream
>>> s = stream(range(5000000)) \
...    .filter(lambda x: str(x)[0] == '3') \
...    .map(lambda x: -x) \
...    .map(lambda x: "Item: %s" % x) \
...    .take(75) \
...    .reverse()
>>> print(s.first_or_else())
Item: -363
>>> print(s.take(5).to_list())
['Item: -363', 'Item: -362', 'Item: -361', 'Item: -360', 'Item: -359']
>>> print(s.take(3).to_string())
Item: -363, Item: -362, Item: -361

Lazy-streams is intended to be a small (single-file), light-weight, simple implementation that relies on a mimimal set of dependencies.

As you can see from the above example, you can stack multiple manipulations on top of each other. The module will optimize the execution to only perform the operations on the elements of the list that are involved in the eventual output.

Also, the original list will remain unchanged as the output of each operation simply returns a delta from the original value.

Documentation and more examples are available docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lazy-streams, version 0.5
Filename, size File type Python version Upload date Hashes
Filename, size lazy_streams-0.5-py3-none-any.whl (6.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size lazy_streams-0.5.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page