Skip to main content

Rich iterator for Python 3

Project description

iter2

This library provides implementation of rich-iterator concept, inspired by Rust's std::iter::Iterator, Java's Stream and more-itertools library.

The original purpose of this tool was to be used within a REPL (primarily IPython) environment for processing streaming data.

The goal of v2.x is to build upon the 7 years of experience gained from the production use of v1.x, to factor out redundant functionality, and to create a well-typed public API.

Usage

iter2 - the main API of this library, behaves like builtin iter but creates an instance of iter2.interfaces.Iterator2.

iter2.interfaces - module with library specific interfaces like Iterator2 and Iterable2.

iter2.algo - module with all algorithms and their curried versions.

iter2.op - module with useful operators like nth_item, pipe and mapping_items.

iter2.box and iter2.option - modules with types of "boxed values" Box2 and Option2.

import typing as tp

from iter2 import iter2


DATA: tp.Sequence[tp.Tuple[str, int | float]] = ...  # type: ignore

result: float | complex = (
    iter2(DATA)
    .filter_unpacked(lambda title, _: (
        title.startswith('Static typing')
    ))  # Iterator2[tp.Tuple[str, int | float]]
    .map_unpacked(lambda _, value: (
        -value,
    ))  # Iterator2[int | float]
    .filter_by_type(float)  # Iterator2[float]
    .apply_raw(
        iter2.algo.find_max_value
    )  # Option2[float]
    .value_or_else(lambda: 31337j)  # float | complex
)

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

iter2-2.0.1746745800.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

iter2-2.0.1746745800-py3-none-any.whl (59.5 kB view details)

Uploaded Python 3

File details

Details for the file iter2-2.0.1746745800.tar.gz.

File metadata

  • Download URL: iter2-2.0.1746745800.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.2 Linux/6.8.0-57-generic

File hashes

Hashes for iter2-2.0.1746745800.tar.gz
Algorithm Hash digest
SHA256 67b39db21177fdc85f654f395d80234c95ad59171c0733f164a0a2d8101c9a73
MD5 3faa87169d88525465a480fc5d36631f
BLAKE2b-256 b0c35584ed6e31f495a4325a99b5e16d3d19a7e9960c822c46f5be09e8e62589

See more details on using hashes here.

File details

Details for the file iter2-2.0.1746745800-py3-none-any.whl.

File metadata

  • Download URL: iter2-2.0.1746745800-py3-none-any.whl
  • Upload date:
  • Size: 59.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.2 Linux/6.8.0-57-generic

File hashes

Hashes for iter2-2.0.1746745800-py3-none-any.whl
Algorithm Hash digest
SHA256 9bcc46897411b2b3aa5705faf976d19d3d7b46934c517ad29bd17907d4b761f3
MD5 5a2d3f5679fd80e8b3246b2437cad432
BLAKE2b-256 922b14ff18d744877194e6ff49dc3cb84d235af49e1382f82657d2048016d318

See more details on using hashes here.

Supported by

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