Skip to content

Instantly share code, notes, and snippets.

@gfx
Created June 1, 2020 05:02
Show Gist options
  • Save gfx/5dae841a13d98c0aee6fbdf7b528eccd to your computer and use it in GitHub Desktop.
Save gfx/5dae841a13d98c0aee6fbdf7b528eccd to your computer and use it in GitHub Desktop.

Revisions

  1. gfx created this gist Jun 1, 2020.
    22 changes: 22 additions & 0 deletions generator.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    function* iterateParams() {
    for (const x of ["a", "b", "c"]) {
    for (const i of [1, 2, 3]) {
    yield { x, i };
    }
    }
    }

    for (const p of iterateParams()) {
    console.log(p);
    }

    // results:
    // { x: 'a', i: 1 }
    // { x: 'a', i: 2 }
    // { x: 'a', i: 3 }
    // { x: 'b', i: 1 }
    // { x: 'b', i: 2 }
    // { x: 'b', i: 3 }
    // { x: 'c', i: 1 }
    // { x: 'c', i: 2 }
    // { x: 'c', i: 3 }