// generator function returns "generators"
// - generators are "iterable iterators".
// - iterators only iterate onceโ
function* genAB() {
yield 'A';
yield 'B';
}
// main
const ab = ['a', 'b']; // array (iterable)
const it = ab.values(); // iterator (iterable)
const AB = genAB(); // generator (iterable iterator)
// โญ arrays can iterate multiple times.
[...ab, ...ab], // [ 'a', 'b', 'a', 'b' ]
// โญ iterators only iterate onceโ
[...it, ...it], // [ 'a', 'b' ]โ
[...AB, ...AB], // [ 'A', 'B' ]โ
// โญ have to call generator function multiple times
// to return multiple new iterators.
[...genAB(), ...genAB()], // [ 'A', 'B', 'A', 'B' ] โญ