Hi,
I've been researching the similarities/differences between Ruby and Python generators (known as Enumerators
in Ruby), and so far as i can tell they're pretty much equivalent.
However one difference i've noticed is that Python Generators support a close()
method whereas Ruby Generators do not. From the Python docs the close()
method is said to do the following:
Raises a GeneratorExit at the point where the generator function was paused. If the generator function then raises StopIteration (by exiting normally, or due to already being closed) or GeneratorExit (by not catching the exception), close returns to its caller."
Is there a good reason why Ruby Enumerators
don't support the close()
method? Or is it an accidental
omission?
I also discovered that Ruby Enumerators
support a rewind()
method yet Python generators do not...is there a reason for this too?
Thanks