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
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:
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.