4 ms·
Especially on StopIteration this is a good way to keep the interface small when lacking static typing. A generator in Java has the has_next() and next() method
by maweki 7y ago
Especially on StopIteration this is a good way to keep the interface small when lacking static typing.
A generator in Java has the has_next() and next() method and this can be statically checked and you're basically only allowed to call next is hasnext is true.
In python the generator only has to provide the next-method and raises an exception when it's exhausted. I don't find this particularly unclean.