Closed
Description
The builtin iter(callable, sentinel)
from pep 234 is not implemented.
The use case is something like this.
with open('file.bin', 'rb') as f:
for chunk in iter(lambda: f.read(128), b''):
process_chunk(chunk)
The two parameter form allows an easy way to make a callable into an iterable by using a sentinel.
It allows for replacing the do while workarounds with a simple iterator.
with open('file.bin', 'rb') as f:
chunk = f.read(128)
while chunk != b'':
process_chunk(chunk)
chunk = f.read(128)
Credit to this stack overflow answer from jfs
https://stackoverflow.com/a/20014805