Skip to content

Commit

Permalink
fix(grid): grids are now iterable again (e.g.: [...grid] or `for (c…
Browse files Browse the repository at this point in the history
…onst hex of grid) {})`)

Using a generator. It's not very performant, but a lot more readable than a custom iterator
method...
  • Loading branch information
flauwekeul committed Apr 22, 2021
1 parent 98c7054 commit c142a68
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export class Grid<T extends Hex> {

constructor(public hexPrototype: T, private traverser: InternalTraverser<T> = infiniteTraverser) {}

[Symbol.iterator]() {
return this.traverser()
*[Symbol.iterator]() {
for (const hex of this.traverser()) {
yield hex
}
}

clone(traverser = this.traverser) {
Expand Down

0 comments on commit c142a68

Please sign in to comment.