Pattern: Generator function without yield
Issue: -
Generator functions that don't use yield are likely a mistake. The purpose of a generator is to yield multiple values. A generator without yield could be written as a regular function returning a single value.
Example of incorrect code:
function* generator() {
return 10;
}
function* emptyGen() {
}
const gen = function*() {
doSomething();
};
Example of correct code:
function* generator() {
yield 1;
yield 2;
return 3;
}
function* range(start, end) {
for (let i = start; i <= end; i++) {
yield i;
}
}
function* gen() {
yield* otherGenerator();
}