function* myCoolGenerator() {}
A generator function creates a Generator!
Exactly the same as Java Iterables or C# Enumerables!!!
function* myCoolGenerator(limit) { // can have 0 or more inputs
for (let i = 1; i <= limit; i++) {
yield i; // produces a value
}
return; // signals that the generator is done
}
for (let element of myCoolGenerator(10)) {
console.log(element);
}
// prints 1, 2, 3, ... , 10
"Generators allow you to define a sequence of elements and process each element as it's produced rather than waiting until the entire sequence is produced"