[Guido]
> The argument that first(it) and next(it) "look the same" doesn't convince
> me;

I'm sorry - I guess then I have absolutely no idea what you were
trying to say, and read it completely wrong.

> if these look the same then all function applications look the same, and
> that can certainly not have been Meertens' intention.

No argument on that from me ;-)

> But if everyone thinks that first() should raise, fine, this thread is way 
> too long
> already (I should have kept it muted :-).

It was being discussed.  The 1-argument more-itertools `first()` does
raise on an exhausted iterator, and that does make most sense to me.
In my algorithms I usually "know" I'm not trying to take an element
from an empty iterable, and have no use for a default value in such a
case.  Since there's no non-destructive way to assert that the
iterable is not exhausted, raising an exception if it is exhausted is
most useful.

    _empty = object()
    a = first(iterable, _empty)
    if a is _empty:
        raise ...

is a PITA by comparison, as is my _current_ idiom:

    for a in iterable:
        break
    else:
        raise ...

Plain old

    a = first(iterable)

would be perfect - but only if it raised.
_______________________________________________
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/4F5YOEB5P2KDRNJGAKGPYN5AUSCYRF7Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to