Function visitor

Visits every cell in grid using supplied selection function In-built functions to use: visitorDepth, visitorBreadth, visitorRandom, visitorColumn, visitorRow.

Usage example:

 let visitor = Grids.visitor(Grids.visitorRandom, grid, startCell);
for (let cell of visitor) {
// do something with cell
}

If you want to keep tabs on the visitor, pass in a MutableValueSet. This is updated with visited cells (and is used internally anyway)

 let visited = new mutableValueSet<Grids.Cell>(c => Grids.cellKeyString(c));
let visitor = Grids.visitor(Grids.visitorRandom, grid, startCell, visited);

To visit with some delay, try this pattern

 const delayMs = 100;
const run = () => {
let cell = visitor.next().value;
if (cell === undefined) return;
// Do something with cell
setTimeout(run, delayMs);
}
setTimeout(run, delayMs);