I have the similarity / differences between the Ruby and Python generators (known as Enumerators
) I'm researching Ruby), and as far as I can tell that they are quite similar
I have noticed a difference that the Python Generator is a close ()
method to support , While Ruby Generators do not. The close ()
method from the Python doc is called to do the following:
Generator frees the generator axis at the paused point. If the generator function then stops stoperation (normally exits, or is already shutting down) or generator acquisition (by catching the exception), the closed return on its collar. "
Good reason that Ruby enumerator
does not support the off () method or is it an accidental default? < / P>
I also found that Ruby enumerator
support Rewind ()
method is not yet a Python generator ... Is there any reason for this? / P>
thanks
This description is slightly below. But to "start" The generator must do one of two things:
- Your Remember the full output, repeat the output again, restart the output
- Reset its internal state in the same way that the same output can be repeated Other unwanted side effects < / Ul>
The second of these is not always possible; For example, if the generator generates byte buffers from the network, the output is not completely the internal state function, but the use of the first technique and Take someone will make a bigger and bigger buffer required memory generator is used because its use. Such generators offer lower performance advantages than the list.
Therefore, I have concluded that Ruby Rewind
should be optional and not always supported by a solid counting class. So if Dragon designers believe that they do not need such a method in all the generators.
Comments
Post a Comment