Break iterators into ordered chunks
Project description
Ordered Demultiplexer in Python
Single pass approach to Demultiplexing/Demuxing
Break an iterator into multiple iterators based on a break filter.
Typical demuxers will place elements into different iterators, such as splitting [0,1,2,3] into ([0,2], [1,3]) based on odd or even elements. Ordered Demuxers focus on breaking iterators into contiguous blocks that are meant to be immediately worked upon, without having to iterate over the list more than once.
This makes them appropriate to use with iterators where the contents cannot be fully held in memory, such as retrieving data online.
Example
With an input such as
[
0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0
]
This can be broken into;
[
[0, 0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0]
]
While leaving the items contained with the iterators, so the return is actually
[
Iterator[Item=int],
Iterator[Item=int],
Iterator[Item=int]
]
Although it requires the consumption of each iterator entirely to make this possible.
Installation
python -m pip install ordered-demuxer
Usage
>>> from ordered_demuxer import FilterCondition, OrderedDemuxer
>>> x = [1, 2, 3, 4]
>>> y = FilterCondition(lambda x: x > 2)
>>> splt = OrderedDemuxer(data_source=iter(x), filter=y, split_after=False)
>>> x_iter = splt.__next__()
>>> print(list(x_iter))
[1, 2]
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
Built Distribution
File details
Details for the file ordered_demuxer-0.0.3.tar.gz
.
File metadata
- Download URL: ordered_demuxer-0.0.3.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91de1bcbf668d09f98409c135af5c886b1a1f9843aff3e7607504c99e76d717b |
|
MD5 | fa5f6cbcc3a42fc60d6a31cdb5a96483 |
|
BLAKE2b-256 | 168accfd2110fae125418ead627e2da3201d6570da1ffb386a540b52c33434f0 |
File details
Details for the file ordered_demuxer-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: ordered_demuxer-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98436303375001c1783a22d64731a2f29893810e421e8e70d0fa970f9496658a |
|
MD5 | 18430e27c559dbc3ee8fa326bff798cf |
|
BLAKE2b-256 | 08aebb28626f8d92f7dcb83126bba29034f9f6822a6d4d9bc6a55bc5f7259ee9 |