Skip to content

streams is a python library to use Java-like stream objects to manipulate iterable collections lazily, offering elementwise exception handling.

License

Notifications You must be signed in to change notification settings

ramsteak/streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

streams

Code style: black tests

About

streams is a python library to use Java-like stream objects to manipulate an iterable collection lazily. In addition it offers elementwise exception handling.

Installation

To install the latest release:

$ py -m pip install https://github.com/ramsteak/streams/releases/download/v1.0.1/streams-1.0.1-py3-none-any.whl

To install the most up-to-date changes:

$ py -m pip install git+https://github.com/ramsteak/streams.git

Usage

from streams import Stream

stream = (Stream.range(10)
            .filter(lambda x:x%2))

stream_list = stream.list()

>>> [1, 3, 5, 7, 9]

The stream object is able to catch exceptions at the item level without interrupting the stream, and the exceptions can be handled with the .exc() method.

stream = (Stream.range(3)
            .eval(lambda x:1/x)
            .exc(ZeroDivisionError, 'replace', float('inf')))

stream_list = stream.list()

>>> [inf, 1.0, 0.5]

Unhandled exceptions will be raised after calling any other method.

stream = (Stream.range(3)
            .eval(lambda x:1/x))
stream_list = stream.list()

>>> ZeroDivisionError: division by zero

See test_use_cases.py for some examples.

About

streams is a python library to use Java-like stream objects to manipulate iterable collections lazily, offering elementwise exception handling.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages