
On Fri, Dec 06, 2019 at 07:27:19PM -0800, Andrew Barnert wrote:
On Dec 6, 2019, at 16:44, Steven D'Aprano <steve@pearwood.info> wrote:
We could, I guess, eliminate the difference by adding the ability to peek ahead to the next value of an arbitrary iterator without consuming that value. This would have to be done by the interpreter, not in Python code,
You can easily wrap an iterator to make it peekable.
Fair enough, in hindsight I'm not sure what I was thinking when I said you couldn't do it from pure Python. Nevertheless, you still have a fundamental problem when it comes to iterators where the value yielded varies in time. Your Peekable wrapper reports the past state of whatever value the underlying iterator produces (the value at the time peek was called), not the current state. -- Steven