May 2018
Intermediate to advanced
380 pages
9h 37m
English
By default, generators provide lazy evaluation: they don't perform a process action until explicitly called. This is a valuable trait when working with large datasets, such as processing millions of calculations. If you attempted to store all the results in memory at one time, that is, via a normal function call, you could run out of space.
Another option is when you don't know if you actually need to use all the values returned. There is no need to perform a calculation if you won't use it, so you can reduce the memory footprint and improve performance.
Still another option is when you want to call another generator or access some other resource, but you want to control when that access occurs. If you don't need an immediate ...