Skip to content

Commit 3e35f67

Browse files
authored
v0.2.1 (#12)
* map method/property example * add tee * add tee and map_dict
1 parent 628126f commit 3e35f67

6 files changed

Lines changed: 346 additions & 29 deletions

File tree

doc/apidoc.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ Returns:
309309

310310

311311

312+
### `map_dict`
313+
314+
Map each item in the iterator using the given dictionary (supports defaultdict).
315+
316+
Args:
317+
mapper (dict[T], U]): The lookup to apply.
318+
319+
Returns:
320+
Itr[U]: An iterator of mapped items.
321+
322+
323+
312324
### `map_while`
313325

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

570582

571583

584+
### `tee`
585+
586+
587+
Create multiple independent Itr wrappers that iterate over the same underlying iterator. NB Consuming any of the
588+
returned iterators will consume the original iterator
589+
590+
This method calls itertools.tee on the wrapped iterator and returns a tuple of Itr
591+
objects, each wrapping one of the tee'd iterators. Each returned Itr yields the same
592+
sequence of items and can be consumed independently of the others.
593+
594+
Parameters
595+
----------
596+
n : int, optional
597+
Number of independent iterators to create (default: 2). Must be >= 1.
598+
599+
Returns
600+
-------
601+
tuple[Itr[T], ...]
602+
Tuple of length `n` containing the newly created Itr objects.
603+
604+
Raises
605+
------
606+
ValueError
607+
If `n` is less than 1.
608+
609+
Notes
610+
-----
611+
- The implementation uses itertools.tee; the tee'd iterators share internal buffers
612+
that store items produced by the original iterator until all tees have consumed them.
613+
If one or more returned iterators lag behind the others, buffered items will be
614+
retained and memory usage can grow.
615+
- After calling this method, avoid consuming the original wrapped iterator (`self._it`)
616+
directly; use the returned Itr objects to prevent surprising interactions with the
617+
shared buffer.
618+
- Creating the tees is inexpensive, but the memory characteristics depend on how the
619+
resulting iterators are consumed relative to each other.
620+
621+
Examples
622+
--------
623+
>>> i = Itr(range(3))
624+
>>> a, b = i.tee(2)
625+
>>> list(a)
626+
[0, 1, 2]
627+
>>> list(b)
628+
[0, 1, 2]
629+
630+
572631
### `unzip`
573632

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

0 commit comments

Comments
 (0)