Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
uv run pytest
- name: Upload coverage report
uses: actions/upload-artifact@v4
if: ${{ (runner.os == 'Linux') && (matrix.python-version == '3.13') }}
with:
name: coverage-html-${{ matrix.os }}-${{ matrix.python-version }}
path: htmlcov/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ __pycache__/
coverage.info

.env
uv.lock
.python-version

.coverage
Expand Down
57 changes: 25 additions & 32 deletions doc/apidoc.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `Itr` v0.2.0 class documentation
# `Itr` v0.2.2 class documentation
A generic iterator adaptor class inspired by Rust's Iterator trait, providing a composable API for
functional-style iteration and transformation over Python iterables.
## Public methods
Expand Down Expand Up @@ -591,41 +591,34 @@ This method calls itertools.tee on the wrapped iterator and returns a tuple of I
objects, each wrapping one of the tee'd iterators. Each returned Itr yields the same
sequence of items and can be consumed independently of the others.

Parameters
----------
n : int, optional
Number of independent iterators to create (default: 2). Must be >= 1.

Returns
-------
tuple[Itr[T], ...]
Tuple of length `n` containing the newly created Itr objects.

Raises
------
ValueError
If `n` is less than 1.
Note:

Notes
-----
- The implementation uses itertools.tee; the tee'd iterators share internal buffers
that store items produced by the original iterator until all tees have consumed them.
If one or more returned iterators lag behind the others, buffered items will be
retained and memory usage can grow.
that store items produced by the original iterator until all tees have consumed them.
If one or more returned iterators lag behind the others, buffered items will be
retained and memory usage can grow.
- After calling this method, avoid consuming the original wrapped iterator (`self._it`)
directly; use the returned Itr objects to prevent surprising interactions with the
shared buffer.
directly; use the returned Itr objects to prevent surprising interactions with the
shared buffer.
- Creating the tees is inexpensive, but the memory characteristics depend on how the
resulting iterators are consumed relative to each other.

Examples
--------
>>> i = Itr(range(3))
>>> a, b = i.tee(2)
>>> list(a)
[0, 1, 2]
>>> list(b)
[0, 1, 2]
resulting iterators are consumed relative to each other.

Args:
n (int, optional): Number of independent iterators to create (default: 2). Must be >= 1.

Returns:
tuple[Itr[T], ...]: Tuple of length `n` containing the newly created Itr objects.

Raises:
ValueError: If `n` is less than 1.

Example:
>>> i = Itr(range(3))
>>> a, b = i.tee(2)
>>> list(a)
[0, 1, 2]
>>> list(b)
[0, 1, 2]


### `unzip`
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "itrx"
version = "0.2.1"
version = "0.2.2"
description = "A chainable iterator adapter"
readme = "README.md"
authors = [
Expand Down
32 changes: 15 additions & 17 deletions src/itrx/itr.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,13 @@ def position(self, predicate: Predicate[T]) -> int:

def product[U](self, other: Iterable[U]) -> "Itr[tuple[T, U]]":
"""
Creates a new iterator over tuples of the combinations of self and the other iterator
Creates a new iterator over the cartesian product of self and the other iterator

Args:
other (Iterable[[T], bool]): Another iterable.

Returns:
Itr[tuple[T, U]]: Iterator of 2-tuples with elements from each input iterator.
"""
return Itr(itertools.product(self._it, other))

Expand Down Expand Up @@ -652,23 +658,16 @@ def tee(self, n: int = 2) -> tuple["Itr[T]", ...]:
objects, each wrapping one of the tee'd iterators. Each returned Itr yields the same
sequence of items and can be consumed independently of the others.

Parameters
----------
n : int, optional
Number of independent iterators to create (default: 2). Must be >= 1.
Args:
n (int, optional): Number of independent iterators to create (default: 2). Must be >= 1.

Returns
-------
tuple[Itr[T], ...]
Tuple of length `n` containing the newly created Itr objects.
Returns:
tuple[Itr[T], ...]: Tuple of length `n` containing the newly created Itr objects.

Raises
------
ValueError
If `n` is less than 1.
Raises:
ValueError: If `n` is less than 1.

Notes
-----
Notes:
- The implementation uses itertools.tee; the tee'd iterators share internal buffers
that store items produced by the original iterator until all tees have consumed them.
If one or more returned iterators lag behind the others, buffered items will be
Expand All @@ -679,8 +678,7 @@ def tee(self, n: int = 2) -> tuple["Itr[T]", ...]:
- Creating the tees is inexpensive, but the memory characteristics depend on how the
resulting iterators are consumed relative to each other.

Examples
--------
Examples:
>>> i = Itr(range(3))
>>> a, b = i.tee(2)
>>> list(a)
Expand Down
Loading