13.12.19 12:45, Steven D'Aprano пише:
On Fri, Dec 13, 2019 at 09:24:20AM +0200, Serhiy Storchaka wrote:
12.12.19 03:22, Stephen J. Turnbull пише:
I would prefer that it not be implemented at all, but
if it is implemented, its behavior should respect the intuition of the
majority of those who want it, which seems to me to be "a variant of
next() that doesn't raise and returns None by default on an empty
iterable."

This is not what the majority expects and is not how first() from
more-itertools works.

I don't know who this majority is, or how you know they are a majority,
but in this thread, the OP Juancarlo's implementation behaved as Stephen
suggested; Guido's version behaved as Stephen suggested; my version
behaved as Stephen suggested.

I don't recall who wants a version of first that raises, or when that
would be useful. It would greatly limit it's usefulness in expressions,
since it needs to be guarded by a try...except.

Yes, Guido's version does not raise, as well as the OP's version. But all others discuss a version which is equivalent to next(iter(iterable)), but raises a ValueError instead of StopIteration. It makes more sense, because such version is less trivial and its use is less errorprone. You can silence an exception by passing the default argument, but getting an exception if first() does not raise is more complex.

If all this time you discussed a version that does not raise, sorry, I missed this.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TF5DH7YWCNOHJUOMYBZ5VDIOICGYRTD4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to