[Christopher Barker <[email protected]>]
> ...
> BTW: this has been a REALLY LONG thread -- I think it's time for a
> concrete proposal to be written up, sonce it appears we're not all
> clear on what we're talking about. For my part I think a first() function
> would be nice, an am open to a couple variations, so someone
> with a stronger opinion should propose something.
>
> Tim: what version do you have in mind?
Same as always: exactly what more-itertools has supplied for years already :-)
If the iterable is empty/exhausted, by default ValueError is raised,
but that can be overridden by also passing an optional argument to
return instead (like dict.pop() in this respect).
So, e.g.,
first([42]) returns 42
first([]) raises ValueError
first([], 42) and first([], default=42) return 42
I don't think it belongs in the builtins. It doesn't perfectly fit
anywhere, but given its prior history in the more-itertools and
itertoolz packages, Python's itertools package seems the least
annoying ;-) home for it.
_______________________________________________
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/VI5DW7LOJVGZ5I3AE56DSWCPQYVKMH6J/
Code of Conduct: http://python.org/psf/codeofconduct/