[Python-ideas] + operator on generators

Wes Turner wes.turner at gmail.com
Sat Jul 1 02:35:29 EDT 2017


On Saturday, July 1, 2017, Steven D'Aprano <steve at pearwood.info> wrote:

> On Fri, Jun 30, 2017 at 01:09:51AM +0200, Jan Kaliszewski wrote:
>
> [...]
>
> But the more I think about it the more I agree with Nick. Let's start
> by moving itertools.chain into built-ins, with zip and map, and only
> consider giving it an operator after we've had a few years of experience
> with chain as a built-in. We might even find that an operator doesn't
> add any real value.


- Would that include chain.from_iterable?
- So there's then a new conditional import (e.g. in a compat package)? What
does this add?


>
> > ¹ Preferably using the existing `yield from` mechanism -- because, in
> > case of generators, it would provide a way to combine ("concatenate")
> > *generators*, preserving semantics of all that their __next__(), send(),
> > throw() nice stuff...
>
> I don't think that would be generally useful.


Flatten one level?


>
> If you're sending values
> into an arbitrary generator, who knows what you're getting? chain() will
> operate on arbitrary iterables, you can't expect to send values into
> chain([1, 2, 3], my_generator(), "xyz") and have anything sensible
> occur.


- is my_generator() mutable (e.g. before or during iteration)?

- https://docs.python.org/2/reference/expressions.html#generator.send
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170701/0a4717e4/attachment.html>


More information about the Python-ideas mailing list