Skip to main content

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

ordered_demuxer-0.0.2.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

ordered_demuxer-0.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file ordered_demuxer-0.0.2.tar.gz.

File metadata

  • Download URL: ordered_demuxer-0.0.2.tar.gz
  • Upload date:
  • Size: 3.0 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

Hashes for ordered_demuxer-0.0.2.tar.gz
Algorithm Hash digest
SHA256 38ec27784bf871eae636424602e72b5fb4b2806e547789cab841c19fe65b0e13
MD5 a97240349f0c49d4ee26b81b6b2ddf80
BLAKE2b-256 846cd05c604128068c3c10aa07b0193ba0e8cffb2f789e31c165430d98b99699

See more details on using hashes here.

File details

Details for the file ordered_demuxer-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ordered_demuxer-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 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

Hashes for ordered_demuxer-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 385cc1f15afe921d90fe26c9dbd0983fef69e18eba8f250ca7d3033923591765
MD5 dc04063506229c3ef698ff4006b3e667
BLAKE2b-256 de4477b0f630d65b4532f6223bc4eeb6d8d17bae202a07f5736b27b9f8c701f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page