-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid): remove map method, add filter and takeWhile methods and a…
…dd inStore helper function Having a map() method on Grid doesn't make much sense: what else than a hex should it map to? takeWhile() stops once the passed predicate returns false. the inStore() helper function can be passed to filter() or takeWhile() to only allow hexes present in the grid's store or an external store (e.g.: `filter(inStore(externalStore))`).
- Loading branch information
1 parent
306dae8
commit 956a2a0
Showing
4 changed files
with
56 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Hex } from '../../hex' | ||
import { Grid } from '../grid' | ||
import { GridStore } from '../types' | ||
|
||
export const inStore = <T extends Hex, S extends GridStore<T>, G extends GridStore<T>>(store?: S) => ( | ||
hex: T, | ||
grid: Grid<T, G>, | ||
): boolean => !!(store ?? grid.store)?.get(hex.toString()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './inStore' | ||
export * from './neighborOf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters