Skip to content
Merged
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
59 changes: 59 additions & 0 deletions doc/apidoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ Returns:



### `map_dict`

Map each item in the iterator using the given dictionary (supports defaultdict).

Args:
mapper (dict[T], U]): The lookup to apply.

Returns:
Itr[U]: An iterator of mapped items.



### `map_while`

Map each item in the iterator using the given function, while the predicate remains True.
Expand Down Expand Up @@ -569,6 +581,53 @@ Returns:



### `tee`


Create multiple independent Itr wrappers that iterate over the same underlying iterator. NB Consuming any of the
returned iterators will consume the original iterator

This method calls itertools.tee on the wrapped iterator and returns a tuple of Itr
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.

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.
- 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.
- 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]


### `unzip`

Splits the iterator of pairs into two separate iterators, each containing the elements from one position of
Expand Down
Loading
Loading