We've seen how the yield
statement is able to pause the execution context of a generator
function, and yield a value back to the calling context. There's a variation on the yield
statement that allows us to defer to other generator
functions. Another technique involves creating a mesh of generators by interweaving several generator sources together. In this section, we'll explore both of these ideas.
Deferring to other generators gives our functions the ability to decide at run-time, to hand off control from one generator to another. In other words, it allows the selection of a more appropriate generator function based on a strategy. Here's a visualization of a generator function that makes a decision and defers to one of several other generator functions:
What we have here are three specialized generators that we would like to use throughout our application. That is, they each work in their own unique way. Perhaps, they're tailored for specific...