-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid/traversers): add repeatWith traverser
It's very similar to branch() but has the option to omit the hexes from the source traverser. Also, the name is a little better (hopefully)
- Loading branch information
1 parent
d7bb59b
commit 8e400af
Showing
5 changed files
with
32 additions
and
5 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,25 @@ | ||
import { Hex } from '../../hex' | ||
import { Traverser } from '../types' | ||
import { concat } from './concat' | ||
|
||
// todo: use in rays (if it still has right to exist) | ||
// todo: probably move repeatWith, repeat and concat to grid/traversers/ | ||
export function repeatWith<T extends Hex>( | ||
sources: Traverser<T> | Traverser<T>[], | ||
targets: Traverser<T> | Traverser<T>[], | ||
// todo: isn't there a more elegant way than a config? | ||
{ includeSource = true } = {}, | ||
): Traverser<T, T[]> { | ||
return function repeatWithTraverser(createHex, cursor) { | ||
const hexes: T[] = [] | ||
|
||
for (const sourceCursor of concat(sources)(createHex, cursor)) { | ||
if (includeSource) hexes.push(sourceCursor) | ||
for (const hex of concat(targets)(createHex, sourceCursor)) { | ||
hexes.push(hex) | ||
} | ||
} | ||
|
||
return hexes | ||
} | ||
} |
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
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