
[Christopher Barker <pythonchb@gmail.com>]
... 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.