Skip to content

Commit

Permalink
Branch coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cjrh committed Oct 23, 2021
1 parent 430d025 commit aa79525
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions excitertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3827,11 +3827,10 @@ def send_also(self, collector: Generator) -> "Iter":
"""
Reference: `more_itertools.consumer <https://more-itertools.readthedocs.io/en/stable/api.html?highlight=numeric_range#more_itertools.consumer>`_
Some ideas around a reverse iterator as a sink. The requirement to
first "next" a just-started generator before you can send values
into it is irritating, but not insurmountable. This method will
automatically detect the "just-started generator" situation, do the
``next()``, and then send in the first value as necessary.
Some ideas around a reverse iterator as a sink. Usually you have
first to "send" a ``None`` into a generator if you want to send
more values into it (or call ``next()`` on it), but we handle
that automatically.
Simple case:
Expand All @@ -3846,6 +3845,22 @@ def send_also(self, collector: Generator) -> "Iter":
>>> output
[0, 1, 2]
However, if the caller already started the generator, that
works too:
.. code-block:: python
>>> output = []
>>> def collector():
... while True:
... output.append((yield))
>>> g = collector()
>>> next(g) # This "starts" the generator
>>> Iter.range(3).send_also(g).collect()
[0, 1, 2]
>>> output
[0, 1, 2]
If the generator is closed before the iteration is complete,
you'll get an exception (Python 3.7+):
Expand Down

0 comments on commit aa79525

Please sign in to comment.