Generators provide a memory-efficient way to iterate over large datasets by producing values one at a time (lazily) using the yield keyword, instead of building an entire array in memory at once. They're ideal for large or streaming data.
yield vs returning an array
{
= [];
( = ; < ; ++) { [] = ; }
;
}
{
( = ; < ; ++) {
;
}
}
(() ) {
();
}
