Generator (computer programming): Difference between revisions

Content deleted Content added
m r2.6.4) (Robot: Modifying pt:Gerador (ciência da computação)
Uses: seq values aren't hard to compute, the wholes are
Line 43:
at which time the innermost loop enclosing the generator invocation is terminated.
 
Because generators compute their yielded values only on demand, they are useful for representing sequences that arewould be expensive or impossible to compute, orat evenonce. These include e.g. infinite sequences and live data streams.
 
In the presence of generators, loop constructs of a language can be reduced into a single loop ... end loop construct; all the usual loop constructs can then be comfortably simulated by using suitable generators in the right way.