Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
cjrh committed Jan 25, 2025
1 parent 337d8a5 commit 67476bb
Showing 1 changed file with 104 additions and 7 deletions.
111 changes: 104 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,18 @@ Replacement for the itertools ``takewhile`` function.
``Iter.tee(self, n=2) -> "Tuple[Self, ...]"``
=============================================
Docstring TODO
Replacement for the itertools ``tee`` function. This version returns
instances of Iter_ to allow further iterable chaining.
.. code-block:: python
>>> a, b = Iter('abc').tee()
>>> a.collect()
['a', 'b', 'c']
>>> b.collect()
['a', 'b', 'c']
.. _Iter.zip_longest:
Expand All @@ -2351,31 +2362,117 @@ Replacement for the itertools ``zip_longest`` function.
``Iter.chunked(self, n: int) -> Self``
======================================
Docstring TODO
Replacement for the more-itertools ``chunked`` function. This version returns
an instance of Iter_ to allow further iterable chaining.
Reference: `more_itertools.chunked <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked>`_
.. code-block:: python
>>> Iter('abcdef').chunked(3).collect()
[['a', 'b', 'c'], ['d', 'e', 'f']]
>>> Iter('abcde').chunked(3).collect()
[['a', 'b', 'c'], ['d', 'e']]
.. _Iter.ichunked:
``Iter.ichunked(self, n: int) -> Self``
=======================================
Docstring TODO
Replacement for the more-itertools ``ichunked`` function. This version returns
an instance of Iter_ to allow further iterable chaining.
This version differs from Iter.chunked_ in that it returns
an iterator of iterators rather than an iterator of lists.
Reference: `more_itertools.ichunked <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.ichunked>`_
.. code-block:: python
>>> Iter('aabbcc').ichunked(3).map(list).collect()
[['a', 'a', 'b'], ['b', 'c', 'c']]
>>> Iter('aabbcc').ichunked(3).map(tuple).collect()
[('a', 'a', 'b'), ('b', 'c', 'c')]
>>> out = Iter('aabbcc').ichunked(3).map(set).collect()
>>> out == [{'a', 'b'}, {'b', 'c'}]
True
.. _Iter.sliced:
``@classmethod Iter.sliced(cls, seq: Sequence, n: int) -> Self``
================================================================
Docstring TODO
|source| ``@classmethod Iter.sliced(cls, seq: Sequence, n: int) -> Self``
=========================================================================
Replacement for the more-itertools ``sliced`` function. This version returns
an instance of Iter_ to allow further iterable chaining.
Reference: `more_itertools.sliced <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.sliced>`_
.. code-block:: python
>>> Iter.sliced('abcdef', 3).collect()
['abc', 'def']
.. _Iter.constrained_batches:
``Iter.constrained_batches(self, max_size: int, max_count=None, get_len=len, strict=True) -> Self``
===================================================================================================
Replacement for the more-itertools ``constrained_batches`` function. This version returns
an instance of Iter_ to allow further iterable chaining.
Reference: `more_itertools.constrained_batches <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.constrained_batches>`_
.. code-block:: python
>>> iterable = [b'12345', b'123', b'12345678', b'1', b'1', b'12', b'1']
>>> Iter(iterable).constrained_batches(10).collect()
[(b'12345', b'123'), (b'12345678', b'1', b'1'), (b'12', b'1')]
>>> Iter(iterable).constrained_batches(10, max_count=2).collect()
[(b'12345', b'123'), (b'12345678', b'1'), (b'1', b'12'), (b'1',)]
.. _Iter.distribute:
``Iter.distribute(self, n: int) -> Self``
=========================================
Docstring TODO
Replacement for the more-itertools ``distribute`` function. This version returns
an instance of Iter_ to allow further iterable chaining.
Reference: `more_itertools.distribute <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.distribute>`_
.. code-block:: python
>>> group_1, group_2, group_3 = Iter('abcdef').distribute(3).collect()
>>> group_1.collect()
['a', 'd']
>>> group_2.collect()
['b', 'e']
>>> group_3.collect()
['c', 'f']
Note that each of the returned iterables is an instance of Iter_, so chaining works.
.. code-block:: python
>>> groups = Iter('abcdef').distribute(3).collect()
>>> groups[0].map(str.upper).collect()
['A', 'D']
.. _Iter.divide:
Expand Down

0 comments on commit 67476bb

Please sign in to comment.