On Fri, Aug 02, 2019 at 11:34:31AM -0700, Christopher Barker wrote:
> As for "consume" -- I think it very much meets the requirement of
> non-trivial and generally useful.
Seems pretty trivial to me:
for x in iterable: pass
ABout a year ago, there was a thread about introducing a keyword, "do", for
those
times you want to run something for its side-effects without collecting
a list of return results. So instead of generating a list of Nones:
[print(x) for x in iterable]
you might call the do statement:
do print(x) for x in iterable
https://mail.python.org/archives/list/[email protected]/thread/2GQW3Q3L2SQ7VFROO2RNR5JV5QQ6HI2D/
Or if you prefer:
do print, iterable
If we had such a keyword, None could be special-cased for consuming an
iterator:
do None, iterable
At the time, I thought "That's a great idea!" and placed a do(func,
iterable) function in my personal toolbox. (See the above thread for a
possible implementation.) And never used it since. So I'm not sure that
my experience agrees with you that consume would be generally useful.
In my experience, most of the time I want to exhaust an iterator
without doing anything with the values produced, I just throw it away:
del iterator
Actually I don't even bother doing that. If I don't want the values
produced by an iterator, I just don't use the iterator.
For consume to be useful, the mere act of accessing the items needs to
have some necessary side-effect that you rely on. Otherwise why bother
to exhaust the iterator, if you can just not use it? This seems like a
code smell to me.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/X4USP6ONHQGDQ4N32GNMWKUP2LVLHQY6/
Code of Conduct: http://python.org/psf/codeofconduct/