A generator is a special type of function which can pause its execution, yield result back to the caller and resume later, at caller’s convenience. And this happens as long as the generator has something to return, some value to yield back. Caller is usually iterating over yielded values in a loop, it takes a new value as soon as generator yields it. The main benefit of generators is that not all elements in a sequence have to be kept in memory at the same time but only a single one.
Generators in Python
Generators in Go
Generators are implemented via channels.
Generators in TypeScript
Generators in C++
C++20: coroutines
Generators in C#
yield return keyword pair is used.