<br><br>On Saturday, July 1, 2017, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, Jul 01, 2017 at 01:35:29AM -0500, Wes Turner wrote:<br>
> On Saturday, July 1, 2017, Steven D'Aprano <<a href="javascript:;" onclick="_e(event, 'cvml', 'steve@pearwood.info')">steve@pearwood.info</a>> wrote:<br>
><br>
> > On Fri, Jun 30, 2017 at 01:09:51AM +0200, Jan Kaliszewski wrote:<br>
> ><br>
> > [...]<br>
> ><br>
> > But the more I think about it the more I agree with Nick. Let's start<br>
> > by moving itertools.chain into built-ins, with zip and map, and only<br>
> > consider giving it an operator after we've had a few years of experience<br>
> > with chain as a built-in. We might even find that an operator doesn't<br>
> > add any real value.<br>
><br>
><br>
> - Would that include chain.from_iterable?<br>
<br>
Yes.<br>
<br>
> - So there's then a new conditional import (e.g. in a compat package)? What<br>
> does this add?<br>
<br>
try:  chain<br>
except NameError:  from itertools import chain<br>
<br>
Two lines, if and only if you both need chain and want to support<br>
versions of Python older than 3.7.<br>
<br>
There's no need to import it if you aren't going to use it.</blockquote><div><br></div><div>Or, can I just continue to import the same function from the same place:</div><div><br></div><div>  from itertools import chain</div><div><br></div><div>Nice, simple, easy. There's even (for all you functional lovers):</div><div><br></div><div>  from itertools import *</div><div><br></div><div>And, again, this works today:</div><div><br></div><div>  from fn import Stream</div><div>  itr = Stream() << my_generator() << (8,9,0)</div><div><br></div><div>- <a href="https://github.com/kachayev/fn.py/blob/master/README.rst#streams-and-infinite-sequences-declaration">https://github.com/kachayev/fn.py/blob/master/README.rst#streams-and-infinite-sequences-declaration</a><br></div><div>  - <a href="https://github.com/kachayev/fn.py/blob/master/fn/stream.py">https://github.com/kachayev/fn.py/blob/master/fn/stream.py</a></div><div><br></div><div>- AFAIU, + doesn't work because e.g. numpy already defines + and & for Iterable arrays.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> > > ¹ Preferably using the existing `yield from` mechanism -- because, in<br>
> > > case of generators, it would provide a way to combine ("concatenate")<br>
> > > *generators*, preserving semantics of all that their __next__(), send(),<br>
> > > throw() nice stuff...<br>
> ><br>
> > I don't think that would be generally useful.<br>
><br>
> Flatten one level?<br>
<br>
Flattening typically applies to lists and sequences.<br>
<br>
I'm not saying that chain shouldn't support generators. That would be<br>
silly: a generator is an iterable and chaining supports iterables. I'm<br>
saying that it wouldn't be helpful to require chain objects to support<br>
send(), throw() etc.</blockquote><div><br></div><div>So the argspec is/shouldbe Iterables with __iter__ (but not necessarily __len__)?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> > If you're sending values<br>
> > into an arbitrary generator, who knows what you're getting? chain() will<br>
> > operate on arbitrary iterables, you can't expect to send values into<br>
> > chain([1, 2, 3], my_generator(), "xyz") and have anything sensible<br>
> > occur.<br>
><br>
><br>
> - is my_generator() mutable (e.g. before or during iteration)?<br>
<br>
It doesn't matter. Sending into a chain of arbitrary iterators isn't a<br>
useful thing to do.</blockquote><div><br></div><div>So, with a generator function, I get a traceback at the current yield statement. With chain() I get whatever line the chain call is on.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> - <a href="https://docs.python.org/2/reference/expressions.html#generator.send" target="_blank">https://docs.python.org/2/<wbr>reference/expressions.html#<wbr>generator.send</a><br>
<br>
Why are you linking to the 2 version of the docs? We're discusing a<br>
hypotheticial new feature which must go into 3, not 2.</blockquote><div><br></div><div>In your opinion, has the send() functionality changed at all?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
--<br>
Steve<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Python-ideas@python.org')">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote>