Skip to content

Commit

Permalink
perf: tiny improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
flauwekeul committed Jul 23, 2022
1 parent 060d39f commit a58c7eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/grid/functions/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import { concat } from './concat'
export function repeat<T extends Hex>(
times: number,
traversers: Traverser<T> | Traverser<T>[],
{ max = 100 } = {},
): Traverser<T, Iterable<T>> {
// todo: generalize this in all traversers that can potentially loop infinitely
// (although in this traverser it doesn't make much sense as `times` is already set explicitly)
if (times > max) {
console.warn(`Traverser created that outputs more hexes (${times}) than configured. Limiting iteration to ${max}.`)
}

const _times = Math.min(times, max)
const repeatedTraversers = Array.from({ length: _times }, () => concat(traversers))
return concat(repeatedTraversers)
return concat(Array.from({ length: times }, () => concat(traversers)))
}
2 changes: 1 addition & 1 deletion src/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Grid<T extends Hex> implements Iterable<T> {
}

toArray(): T[] {
return [...this]
return Array.from(this)
}

// todo: implement like so:
Expand Down

0 comments on commit a58c7eb

Please sign in to comment.