What does yield mean in PHP?

What is yield? The yield keyword returns data from a generator function: The heart of a generator function is the yield keyword. In its simplest form, a yield statement looks much like a return statement, except that instead of stopping execution of the function and returning, yield instead provides a value to the code looping … Read more

Return in generator together with yield

This is a new feature in Python 3.3 (as a comment notes, it doesn’t even work in 3.2). Much like return in a generator has long been equivalent to raise StopIteration(), return <something> in a generator is now equivalent to raise StopIteration(<something>). For that reason, the exception you’re seeing should be printed as StopIteration: 3, … Read more

What can we do with ES6 Generator that we cannot with for loop?

By using yield, generators can be suspended at any point in the control flow of your function, saving your current state of execution (scope & stack). Without generators, this is more complicated: you need to explicitly keep track of the state branching and (especially) looping control structures need to be represented in a functional way, … Read more

What is a CMake generator?

What’s a generator? To understand what a generator is, we need to first look at what is a build system. CMake doesn’t compile or link any source files. It used a generator to create configuration files for a build system. The build system uses those files to compile and link source code files. So what’s … Read more

Python: using a recursive algorithm as a generator

def getPermutations(string, prefix=””): if len(string) == 1: yield prefix + string else: for i in xrange(len(string)): for perm in getPermutations(string[:i] + string[i+1:], prefix+string[i]): yield perm Or without an accumulator: def getPermutations(string): if len(string) == 1: yield string else: for i in xrange(len(string)): for perm in getPermutations(string[:i] + string[i+1:]): yield string[i] + perm